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];
|
char url[COAP_OBSERVER_URL_LEN];
|
||||||
|
|
||||||
url_len = strlen(resource->url);
|
url_len = strlen(resource->url);
|
||||||
strncpy(url, resource->url, COAP_OBSERVER_URL_LEN);
|
strncpy(url, resource->url, COAP_OBSERVER_URL_LEN - 1);
|
||||||
if(strlen(url) < COAP_OBSERVER_URL_LEN && subpath != NULL) {
|
if(url_len < COAP_OBSERVER_URL_LEN - 1 && subpath != NULL) {
|
||||||
strncpy(&url[url_len], subpath, COAP_OBSERVER_URL_LEN - url_len);
|
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 */
|
/* url now contains the notify URL that needs to match the observer */
|
||||||
PRINTF("Observe: Notification from %s\n", url);
|
PRINTF("Observe: Notification from %s\n", url);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue