Skip to content
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

Merged
merged 1 commit into from
Nov 22, 2018

Conversation

kb2ma
Copy link
Member

@kb2ma kb2ma commented Oct 22, 2018

Contribution description

Both the nanocoap coap_opt_put_string() and coap_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'.

@kb2ma kb2ma added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: CoAP Area: Constrained Application Protocol implementations labels Oct 22, 2018
@kb2ma kb2ma self-assigned this Oct 22, 2018
@bergzand bergzand self-assigned this Oct 22, 2018
Copy link
Contributor

@haukepetersen haukepetersen left a 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.

sys/net/application_layer/nanocoap/nanocoap.c Outdated Show resolved Hide resolved
sys/net/application_layer/nanocoap/nanocoap.c Outdated Show resolved Hide resolved
@haukepetersen haukepetersen added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Nov 21, 2018
Copy link
Contributor

@haukepetersen haukepetersen left a 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.
@kb2ma kb2ma force-pushed the nanocoap/string_opt_first_char branch from 081b640 to fa77929 Compare November 22, 2018 14:29
@kb2ma kb2ma added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 22, 2018
@kb2ma
Copy link
Member Author

kb2ma commented Nov 22, 2018

Yay, our automated overlords have been appeased! I will rebase #9156 after the merge.

@miri64 miri64 merged commit 7816497 into RIOT-OS:master Nov 22, 2018
@aabadie aabadie added this to the Release 2019.01 milestone Dec 2, 2018
@kb2ma kb2ma deleted the nanocoap/string_opt_first_char branch February 4, 2019 23:06
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 CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants