You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CoAP server reads incoming packets from the UDP socket using recvfrom, which silently truncates messages if they don't fit into the buffer (see Socket API docs here).
There is an assertion which checks the returned length. However, this assertion will never fail as long as the Socket API is implemented correctly.
Build some code that uses the CoAP server, e.g. samples/net/sockets/coap_server
Send a CoAP request that is larger than CONFIG_COAP_SERVER_MESSAGE_SIZE.
Observe that the message is silently truncated.
Expected behavior
The CoAP server should not further process incomplete CoAP messages. It should also not respond to the client with an ACK, but with 4.13 Request Entity Too Largeinstead.
Impact
Buffers must be oversized to avoid undefined behavior, as incoming request length is usually not fully predictable at compile-time.
Environment (please complete the following information):
Please test #83758 if this fixes your issue.
One comment though, is that the "4.13 Request Entity Too Large" is a response code which should still be done with an ACK in case of a confirmable message, I think.
Wow, thank you very much for the quick fix. Yeah, sure, you're right. It's still an ACK, but with an error code.
I will test it tomorrow and let you know the result.
martinjaeger
changed the title
CoAP server should not silently truncate and ACK too long requests
CoAP server should not silently truncate too long requests
Jan 9, 2025
Describe the bug
The CoAP server reads incoming packets from the UDP socket using
recvfrom
, which silently truncates messages if they don't fit into the buffer (see Socket API docs here).There is an assertion which checks the returned length. However, this assertion will never fail as long as the Socket API is implemented correctly.
zephyr/subsys/net/lib/coap/coap_server.c
Lines 139 to 141 in d78952b
To Reproduce
Steps to reproduce the behavior:
samples/net/sockets/coap_server
CONFIG_COAP_SERVER_MESSAGE_SIZE
.Expected behavior
The CoAP server should not further process incomplete CoAP messages. It should
also notrespond to the clientwith an ACK, butwith 4.13 Request Entity Too Largeinstead.Impact
Buffers must be oversized to avoid undefined behavior, as incoming request length is usually not fully predictable at compile-time.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: