-
Notifications
You must be signed in to change notification settings - Fork 2.1k
nanocoap: avoid non static
buffers of configurable size
#21270
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
Merged
Merged
Conversation
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
benpicco
reviewed
Mar 6, 2025
mguetschow
approved these changes
Mar 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Area: CoAP
Area: Constrained Application Protocol implementations
Area: network
Area: Networking
Area: sys
Area: System
Area: tests
Area: tests and testing framework
CI: no fast fail
don't abort PR build after first error
CI: ready for build
If set, CI server will compile all applications for all available boards for the labeled PR
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-
static
uint8_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
nanocoap
functions. 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-xpro
and 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/ttyACM0
On
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