-
Notifications
You must be signed in to change notification settings - Fork 8k
net: sockets: getaddrinfo() buffer overflow, etc. fixes #6158
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: sockets: getaddrinfo() buffer overflow, etc. fixes #6158
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6158 +/- ##
==========================================
- Coverage 52.88% 52.87% -0.01%
==========================================
Files 412 412
Lines 40274 40278 +4
Branches 7801 7802 +1
==========================================
Hits 21297 21297
- Misses 15761 15765 +4
Partials 3216 3216
Continue to review full report at Codecov.
|
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.
Good catch. Please also modify line 34 so that the pointer isn't even calculated if state->idx
is out of bounds (it's undefined behavior); I can't seem to be able to comment in that line as it's not part of your patch.
Are you sure that calculation is undefined behavior? Maybe accessing a pointer calculated in such a manner is undefined behavior? |
Yes, I'm sure. The only exception is calculating the pointer to one element past the end of an array (so it's possible to loop through an array using pointers rather than indices). See the C11 text, 6.5.6.8:
|
The existing implementation assumed DNS resolv callback will be called just once, but that's not always the case (apparently, for multi-homes hosts or something). So, apply array bounds checking (and do pointer arithmetic only after it, as the C standard otherwise warns of "undefined behavior"). In such a case, the port number wasn't set in each entry too, so rework how it's done. The issues discovered while resolving archive.ubuntu.com. Signed-off-by: Paul Sokolovsky <[email protected]>
f94d3ee
to
3953714
Compare
Updated as suggested. |
Note for whoever is merging this: this should be backported to 1.10. |
@pfalcon can you backport and submit to 1.10 branch? |
Submitted as #6169, thanks. |
The existing implementation assumed DNS resolv callback will be
called just once, but that's not always the case (apparently,
for multi-homes hosts or something). So, apply array bounds
checking. In this case, port number wasn't set in each entry too,
so rework how it's done.
The issues discovered while resolving archive.ubuntu.com.
Signed-off-by: Paul Sokolovsky [email protected]