1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-15 01:23:49 +01:00

examples: check return value of coap_build_reply()

`coap_build_reply()` may return negative values on error or
0 in the no-response case.

Don't use it to calculate a payload offset without checking first.
This commit is contained in:
Benjamin Valentin 2022-11-04 20:00:51 +01:00
parent 0284aa5146
commit 4fe202db1e
2 changed files with 8 additions and 0 deletions

View File

@ -150,6 +150,10 @@ ssize_t _sha256_handler(coap_pkt_t* pkt, uint8_t *buf, size_t len, coap_request_
}
ssize_t reply_len = coap_build_reply(pkt, result, buf, len, 0);
if (reply_len <= 0) {
return reply_len;
}
uint8_t *pkt_pos = (uint8_t*)pkt->hdr + reply_len;
if (blockwise) {
pkt_pos += coap_opt_put_block1_control(pkt_pos, 0, &block1);

View File

@ -66,6 +66,10 @@ ssize_t _flashwrite_handler(coap_pkt_t* pkt, uint8_t *buf, size_t len, coap_requ
}
ssize_t reply_len = coap_build_reply(pkt, result, buf, len, 0);
if (reply_len <= 0) {
return reply_len;
}
uint8_t *pkt_pos = (uint8_t*)pkt->hdr + reply_len;
pkt_pos += coap_put_block1_ok(pkt_pos, &block1, 0);