sys/net/nanocoap: fix buffer overflow in separate response handling [backport 2024.10] #21087
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.
(Partial) Backport of #21075
Contribution description
When RFC 8974 support (module
nanocoap_token_ext
) is in use, the request token may be longer than the buffer in the separate response context is large. This adds a check to not overflow the buffer.Sadly, this is an API change: Preparing the separate response context can actually fail, so we need to report this with a return value.
The example application has been adapted to only proceed if the separate reply context could have been prepared, and rather directly emit a reset message if the token exceeds the static buffer.
Testing procedure
This requires a client from
master
, as extending the test to allow specifying the token is not backported.Preparation
Running the Server
This should be done with
2024.10-branch
and this PRcopy the
<IPV6_ADDR>
part of the outputRunning the Client
This should be done with
master
.Expected result: No segfault in the server
Issues/PRs references
Partial backport of #21075