nanocoap: avoid non static buffers of configurable size #21270
Merged
fabian18 merged 2 commits intoRIOT-OS:masterfrom Apr 1, 2025
Merged
nanocoap: avoid non static buffers of configurable size #21270fabian18 merged 2 commits intoRIOT-OS:masterfrom
static buffers of configurable size #21270fabian18 merged 2 commits intoRIOT-OS:masterfrom
Conversation
benpicco
reviewed
Mar 6, 2025
mguetschow
approved these changes
Mar 10, 2025
Contributor
mguetschow
left a comment
There was a problem hiding this comment.
LGTM! Let's see what else the CI comes up with, then feel free to squash!
benpicco
reviewed
Mar 12, 2025
c64d701 to
7f22009
Compare
7f22009 to
51ac476
Compare
51ac476 to
b07e095
Compare
b07e095 to
49243a5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
How often have you been looking for a bug, and it felt like chasing a ghost because memory was messed up?
How often was it a buffer you have unsuspectingly increased in size, which was not
static?(The right answer is: Yes 😄)
That's why non-
staticuint8_t buffer[CONFIG_INCREASE_ON_DEMAND]is likely a footgun.Most importantly, this PR makes that a response buffer for
nanocoap_link_format_get()has to be user allocated.I could have just made it
static, but this would bring up a concurrency issue.Secondly, a buffer
[CONFIG_NANOCOAP_BLOCK_HEADER_MAX]is added tonanocoap_sock_t.This was before allocated in various
nanocoapfunctions. I moved it to the socket because this is likely allocated in a user thread. Therefore the stack size of that user's thread is no longer our problem 😅. And not so unlikely, the user allocates the socket withstatic.Testing procedure
Start a CoAP fileserver:
aiocoap-fileserver --bind [::] .Flash a
sam54-xproand connect it via ethernet to the coap fileserver:USEMODULE+=nanocoap_vfs CFLAGS+=-DCONFIG_NANOCOAP_QS_MAX=1024 BOARD=same54-xpro make -C examples/networking/gnrc/gnrc_networking flash term PORT=/dev/ttyACM0On
master:ncget coap://[fe80::be63:bb80:6473:faa9]/crashes on my setup.On this banch it succeeds and prints the directory content.
Issues/PRs references