-
Notifications
You must be signed in to change notification settings - Fork 3k
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
nsapi - Fix leftover bytes from suffix during ipv6 parsing #2953
Conversation
/morph test-nightly |
@@ -122,6 +122,7 @@ static void ipv6_from_address(uint8_t *bytes, const char *addr) | |||
// Move suffix to end | |||
memmove(&shorts[NSAPI_IPv6_BYTES/2-suffix], &shorts[0], | |||
suffix*sizeof(uint16_t)); | |||
memset(&shorts[0], 0, suffix*sizeof(uint16_t)); |
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.
You might want to assert size of suffix to catch overflows before they occur.
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.
This memset solution not more expensive (slower you are writing 2x bytes instead of 1x words (uint16_t) ). The variable shorts
is already a uint16_t.
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.
@c1728p9, the value of suffix
is bounded by this loop:
https://github.com/geky/mbed/blob/16c4da03e62fc2367b33be8bb9358c28804fffb3/features/netsocket/SocketAddress.cpp#L88
I don't think there is much value to adding an assert at this granularity, there are many other points of failure in this function.
@EduardPon, memset
and friends can be optimized quite heavily by the compiler, usually emitting word-aligned assignments. The loop may be quicker, but without a test to check which is faster I just went with the higher-level operation.
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 reason I mention adding an assert is because you have no array bounds check for shorts and you get the size to zero from a separate function. Clobbered stacks can be tricky to track down, since a crash typically occurs on the function return.
Result: FAILUREYour command has finished executing! Here's what you wrote!
Outputmbed Build Number: 1070 Test failed! |
Fix is good. You'll find another set of 12 useful tests in the IPv6<->string conversion functions over in Nanomesh libservice: https://github.com/ARMmbed/nanostack-libservice/ Covers all the tricky cases from RFC 5952, but most of the trickiness is actually in binary->string conversion. Of course, we could just use the existing implementations from there. Seems a bit silly debugging or improving these implementations when we already have a fully-compliant pair. Believe the only problem is its locked behind FEATURE_COMMON_PAL (and the name "nanostack" in the path). Enable that feature for netsocket? |
@@ -122,6 +122,7 @@ static void ipv6_from_address(uint8_t *bytes, const char *addr) | |||
// Move suffix to end | |||
memmove(&shorts[NSAPI_IPv6_BYTES/2-suffix], &shorts[0], | |||
suffix*sizeof(uint16_t)); | |||
memset(&shorts[0], 0, suffix*sizeof(uint16_t)); |
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.
I think that length of the memset should be (NSAPI_IPv6_BYTES/2-suffix)*sizeof(uint16_t)
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 remaining space has already been zeroed out by the previous memset:
https://github.com/geky/mbed/blob/16c4da03e62fc2367b33be8bb9358c28804fffb3/features/netsocket/SocketAddress.cpp#L110
Either way would work
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.
If suffix is long memsetting suffix size can overwrite the beginning of memmoved suffix e.g.
if address is 2001::db8:1111:2222:3333:4444
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.
Ah good point, this should be updated
It would be a good idea to adopt the nanomesh ipv6 parsing and tests. I'm hesitant to create another dependency on In the meantime this patch provides a fix for the current implementation. |
16c4da0
to
17b1136
Compare
/morph test-nightly |
Result: FAILUREYour command has finished executing! Here's what you wrote!
Outputmbed Build Number: 1077 Test failed! |
I reviewed some of the failures, I would highlight these: NRF51_DK-GCC_ARM.tests-netsocket-ip_parsing.Simple IPv4 address |
Thanks to @EduardPon for hunting this down
17b1136
to
52ceaf9
Compare
/morph test-nightly |
52ceaf9
to
cce82b1
Compare
/morph test-nightly |
Result: FAILUREYour command has finished executing! Here's what you wrote!
Outputmbed Build Number: 917 Test failed! |
Result: FAILUREYour command has finished executing! Here's what you wrote!
Outputmbed Build Number: 918 Test failed! |
Looks like the results are good 👍 Failing tests are the lp_ticker for the NCS36510 |
Thanks to @EduardPon for hunting this down:
fixes #2931