-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gcoap_fileserver: can't deal with 16 byte block size #20686
Comments
It happens because first we assume The issue is that an option written to a buffer is rewritten with a smaller option length, because the option value bacame actually 0. |
Thank you, that explanation makes perfect sense! |
The CoAP block option gets written twice: First a 'dummy' value is written by `coap_opt_add_block2()`, later this gets overwritten by the real option value by coap_block2_finish(). The problem arises when the size of the option changes. If the option ends up smaller than the dummy, we have garbage bytes after the real option value, corrupting the packet. To mitigate this, always write at least one option byte (which will be a 0 byte) to ensure the dummy data is overwritten. fixes RIOT-OS#20686
The CoAP block option gets written twice: First a 'dummy' value is written by `coap_opt_add_block2()`, later this gets overwritten by the real option value by coap_block2_finish(). The problem arises when the size of the option changes. If the option ends up smaller than the dummy, we have garbage bytes after the real option value, corrupting the packet. To mitigate this, always write at least one option byte (which will be a 0 byte) to ensure the dummy data is overwritten. fixes RIOT-OS#20686
Description
When requesting 16 byte block size, the server will respond with an invalid packet.
Steps to reproduce the issue
run
examples/gcoap_fileserver
:create a dummy file
Try to access the file via e.g.
ncget
with a 16 byte block sizeExpected results
We get the response in a single block
Actual results
We get the response in a single block, but there is some garbage after the block2 option:
gcoap_fileserver.pcapng.gz
Versions
RIOT master
The text was updated successfully, but these errors were encountered: