-
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
net/nanocoap: fix string option separator write handling #10223
Conversation
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.
The proposed changes are valid and work as far as I can tell (after some testing).
Just this one question on optimization of the code, else I think the PR is ready to be merged.
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.
ACK, please squash
Assumed initial character was a separator when writing the option, and skipped over it.
081b640
to
fa77929
Compare
Yay, our automated overlords have been appeased! I will rebase #9156 after the merge. |
Contribution description
Both the nanocoap
coap_opt_put_string()
andcoap_opt_add_string()
functions assume the first character in the string is a separator, and skip over it when writing the (first) option. This behavior likely resulted from our initial handling of Path strings. For a path we usually send the full concatenated path as a single string, which always starts with a '/', at least for a Uri-Path option.However, for a Uri-Query we usually send each query individually, for example in the
cord_common_add_qstring()
function, and we don't expect to start the query key with an '&'.The error is not expressed currently in the cord module because gcoap uses an older mechanism to write a query option. I'm trying to update how gcoap writes options in some other work, and encountered the problem.
Testing procedure
Probably the easiest way to test is to copy/paste the included unit test, test_nanocoap__get_query() into the tests-nanocoap unit test in master. It tries to add the query string 'ab=cde'. You'll see the test fails because the length of the option is short by one. It neglects to write the first character in the key, so the option contains 'b=cde'.