Skip to content

Commit

Permalink
Merge #19994
Browse files Browse the repository at this point in the history
19994: nanocoap: prevent integer underflow in coap_opt_put_uri_pathquery() r=miri64 a=benpicco





Co-authored-by: Benjamin Valentin <[email protected]>
  • Loading branch information
bors[bot] and benpicco authored Oct 24, 2023
2 parents a1e1931 + 0fa04a3 commit 61ae692
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,15 @@ size_t coap_opt_put_string_with_len(uint8_t *buf, uint16_t lastonum, uint16_t op

size_t coap_opt_put_uri_pathquery(uint8_t *buf, uint16_t *lastonum, const char *uri)
{
size_t len;
const char *query = strchr(uri, '?');
size_t len = query ? (size_t)(query - uri - 1) : strlen(uri);

if (query) {
len = (query == uri) ? 0 : (query - uri - 1);
} else {
len = strlen(uri);
}

size_t bytes_out = coap_opt_put_string_with_len(buf, *lastonum,
COAP_OPT_URI_PATH,
uri, len, '/');
Expand Down

0 comments on commit 61ae692

Please sign in to comment.