Skip to content

Commit

Permalink
fixup! sys/net/nanocoap: fix coap_build_reply_header()
Browse files Browse the repository at this point in the history
  • Loading branch information
maribu committed Nov 4, 2024
1 parent bc2b30f commit 9085340
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,20 +592,21 @@ ssize_t coap_build_reply_header(coap_pkt_t *pkt, unsigned code,
}
}

/* we need to update the header length with the actual one, as we may have
* used less bytes for the extended token length fields as our worst case
* assumption */
hdr_len = bufpos - (uint8_t *)buf;

if (payload) {
if (ct >= 0) {
bufpos += coap_put_option_ct(bufpos, 0, ct);
}
*bufpos++ = COAP_PAYLOAD_MARKER;
hdr_len = bufpos - (uint8_t *)buf;
*payload = bufpos;
*payload_len_max = len - hdr_len;
}

/* we need to update the header length with the actual one, as we may have
* used less bytes for the extended token length fields as our worst case
* assumption */
hdr_len = bufpos - (uint8_t *)buf;

/* with the nanoCoAP API we can't detect the overflow before it happens */
assert(hdr_len <= len);

Expand Down

0 comments on commit 9085340

Please sign in to comment.