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:
parent
16afb4b74c
commit
058ae7bae3
|
@ -189,8 +189,10 @@ void generic_put_handler
|
||||||
|
|
||||||
if (from_str && (len = coap_get_payload(request, &bytes))) {
|
if (from_str && (len = coap_get_payload(request, &bytes))) {
|
||||||
if (c_ctype == REST.type.TEXT_PLAIN) {
|
if (c_ctype == REST.type.TEXT_PLAIN) {
|
||||||
|
int l = MIN (len, sizeof (temp) - 1);
|
||||||
temp [sizeof (temp) - 1] = 0;
|
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
|
} else { // jSON Format
|
||||||
if (json_parse_variable (bytes, len, name, temp, sizeof (temp)) < 0) {
|
if (json_parse_variable (bytes, len, name, temp, sizeof (temp)) < 0) {
|
||||||
success = 0;
|
success = 0;
|
||||||
|
|
|
@ -203,18 +203,7 @@ PROCESS_THREAD(poti, ev, data)
|
||||||
char buf [4];
|
char buf [4];
|
||||||
coap_transaction_t *transaction;
|
coap_transaction_t *transaction;
|
||||||
|
|
||||||
/*
|
sprintf (buf, "%d", val);
|
||||||
* 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);
|
|
||||||
lastval = val;
|
lastval = val;
|
||||||
printf ("Sending Value: %s\n", buf);
|
printf ("Sending Value: %s\n", buf);
|
||||||
coap_init_message (request, COAP_TYPE_NON, COAP_PUT, 0);
|
coap_init_message (request, COAP_TYPE_NON, COAP_PUT, 0);
|
||||||
|
|
Loading…
Reference in a new issue