mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-11-05 19:07:41 +00:00
Make sure the url is null terminated in CoAP observe.
This commit is contained in:
parent
7edf6e60e9
commit
d764e09f35
@ -196,10 +196,12 @@ coap_notify_observers_sub(resource_t *resource, const char *subpath)
|
||||
char url[COAP_OBSERVER_URL_LEN];
|
||||
|
||||
url_len = strlen(resource->url);
|
||||
strncpy(url, resource->url, COAP_OBSERVER_URL_LEN);
|
||||
if(strlen(url) < COAP_OBSERVER_URL_LEN && subpath != NULL) {
|
||||
strncpy(&url[url_len], subpath, COAP_OBSERVER_URL_LEN - url_len);
|
||||
strncpy(url, resource->url, COAP_OBSERVER_URL_LEN - 1);
|
||||
if(url_len < COAP_OBSERVER_URL_LEN - 1 && subpath != NULL) {
|
||||
strncpy(&url[url_len], subpath, COAP_OBSERVER_URL_LEN - url_len - 1);
|
||||
}
|
||||
/* Ensure url is null terminated because strncpy does not guarantee this */
|
||||
url[COAP_OBSERVER_URL_LEN - 1] = '\0';
|
||||
/* url now contains the notify URL that needs to match the observer */
|
||||
PRINTF("Observe: Notification from %s\n", url);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user