-
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
nanocoap: defuse footgun in coap_get_uri_query() #20195
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -847,18 +847,18 @@ | |
* This function decodes the pkt's URI_QUERY option into a "&"-separated and | ||
* '\0'-terminated string. | ||
* | ||
* Caller must ensure @p target can hold at least CONFIG_NANOCOAP_URI_MAX bytes! | ||
* | ||
* @param[in] pkt pkt to work on | ||
* @param[out] target buffer for target URI | ||
* @param[in] max_len size of @p target in bytes | ||
* | ||
* @returns -ENOSPC if URI option is larger than CONFIG_NANOCOAP_URI_MAX | ||
* @returns -ENOSPC if URI option is larger than @p max_len | ||
* @returns nr of bytes written to @p target (including '\0') | ||
*/ | ||
static inline ssize_t coap_get_uri_query(coap_pkt_t *pkt, uint8_t *target) | ||
static inline ssize_t coap_get_uri_query_string(coap_pkt_t *pkt, char *target, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing this to |
||
size_t max_len) | ||
{ | ||
return coap_opt_get_string(pkt, COAP_OPT_URI_QUERY, target, | ||
CONFIG_NANOCOAP_URI_MAX, '&'); | ||
return coap_opt_get_string(pkt, COAP_OPT_URI_QUERY, | ||
(uint8_t *)target, max_len, '&'); | ||
} | ||
|
||
/** | ||
|
@@ -1826,7 +1826,7 @@ | |
* | ||
* @returns amount of bytes written to @p buf | ||
*/ | ||
size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const void *odata, size_t olen); | ||
|
||
/** | ||
* @brief Insert block1 option into buffer | ||
|
@@ -2214,4 +2214,4 @@ | |
} | ||
#endif | ||
#endif /* NET_NANOCOAP_H */ | ||
/** @} */ | ||
This file contains 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
Oops, something went wrong.
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.
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.
Part of the footgun (IMO the bigger footgun even) is that this function drives people toward assembling and later parsing this string, which inevitably leads to trouble once the first
&
appears in a query parameter (and if that were fixed, the string would go through percent encoding and then back again).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.
Scratch that -- we'll still need such a note, but #20197 adds something that would be pointed to instead.