Files
libcoap/include
Alejandro Pacheco cfa1cf3d17 coap_block.c: Body length of a reassembled body is where the last block ends
When a block-wise body is passed on as a single body, its length was taken
from total_len, which tracks the peer's Size2 / Size1 rather than the data
actually received.

Client Q-Block2: total_len was raised to a larger Size2 in a later block
before the Size2 mismatch check, so the check never fired for that case,
and nothing tied the last block to Size2. The body handed to the
application could then be longer than the data buffer behind it, or
include its uninitialised tail.

Server Block1 / Q-Block1: total_len kept a Size1 that was larger than
where the last block ended, so the body included the uninitialised tail
of the buffer allocated for the Size1 estimate.

Now the last block (M bit not set) defines the body length: for Q-Block2
and Q-Block1 it must end at Size2 / Size1 (RFC9177 requires these to be the
full size), and for Block1 / Block2 it replaces the Size2 / Size1 estimate
(RFC7959 4). A new total_len_set flag records that the last block has set
total_len, after which a block that ends past it, or another last block
that ends elsewhere, is rejected instead of changing the length.

Add unit tests to tests/test_block.c.
2026-10-16 15:01:00 +01:00
..