From 5d6ae60ee0ce5fba9279bc5178c5ac7b50240e71 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 23 Jan 2024 14:31:16 +0100 Subject: [PATCH] fixup! nanocoap: add coap_build_reply_header() --- sys/net/application_layer/nanocoap/nanocoap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index 36f51f86970f..db911dc0741e 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -591,10 +591,14 @@ ssize_t coap_build_reply_header(coap_pkt_t *pkt, unsigned code, } *bufpos++ = COAP_PAYLOAD_MARKER; *payload = bufpos; - *payload_len_max = len - (bufpos - (uint8_t *)buf); + hdr_len = bufpos - (uint8_t *)buf; + *payload_len_max = len - hdr_len; } - return bufpos - (uint8_t *)buf; + /* with the nanoCoAP API we can't detect the overflow before it happens */ + assert(hdr_len <= len); + + return hdr_len; } ssize_t coap_reply_simple(coap_pkt_t *pkt,