Alleged race-condition was a bug in receiver

Handling put-requests was missing a trailing \0 in the parsed string.
This commit is contained in:
Ralf Schlatterbeck 2015-01-27 10:43:03 +01:00
parent 16afb4b74c
commit 058ae7bae3
2 changed files with 4 additions and 13 deletions

View file

@ -189,8 +189,10 @@ void generic_put_handler
if (from_str && (len = coap_get_payload(request, &bytes))) {
if (c_ctype == REST.type.TEXT_PLAIN) {
int l = MIN (len, sizeof (temp) - 1);
temp [sizeof (temp) - 1] = 0;
strncpy (temp, (const char *)bytes, MIN (len, sizeof (temp) - 1));
strncpy (temp, (const char *)bytes, l);
temp [l] = 0;
} else { // jSON Format
if (json_parse_variable (bytes, len, name, temp, sizeof (temp)) < 0) {
success = 0;

View file

@ -203,18 +203,7 @@ PROCESS_THREAD(poti, ev, data)
char buf [4];
coap_transaction_t *transaction;
/*
* Note: A sending transaction may be still in progress when
* we call the following code. This means that the *new*
* value in the transaction buffer will overwrite the old
* value *but* the old length remains. This means if we
* first send 255 (and the transaction sending 255 is still
* in progress) and we now send 0, the resulting buffer is
* 055 (because only the 0 is copied but the old length
* stays). Therefore as a workaround we *always* send a
* 3-byte value.
*/
sprintf (buf, "%03d", val);
sprintf (buf, "%d", val);
lastval = val;
printf ("Sending Value: %s\n", buf);
coap_init_message (request, COAP_TYPE_NON, COAP_PUT, 0);