fix(http): reject out-of-range listening ports - #4320
Conversation
|
|
|
Thanks for picking this up, and the fix reads right to me. Two things that are easier to sort out now than after review. The description says #4292 is approved and touches the same part of I can answer anything about the issue if that helps. |
|
Thanks for catching that. I updated the description to use Fixes #4305 instead of closing the audit tracker. I’ll rebase once #4292 lands and resolve any overlap in socket_tools.h. I’ll also move the port validation coverage into ext/test/http/socket_tools_test.cc after the rebase, since that sounds like the better location for the constructor-level tests. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4320 +/- ##
==========================================
- Coverage 80.87% 80.86% -0.01%
==========================================
Files 450 450
Lines 19186 19190 +4
==========================================
+ Hits 15515 15516 +1
- Misses 3671 3674 +3
🚀 New features to boost your workflow:
|
|
Thanks again for the guidance. I rebased onto the merged #4292 changes, moved the integer The focused Bazel test passes locally. Let me know if any other suggestions arise please! |
dbarker
left a comment
There was a problem hiding this comment.
Thanks for the pr. This impacts internal http server used in testing and the http example. Not for production use.
| if (port < 0 || port > 65535) | ||
| { | ||
| return; | ||
| } | ||
|
|
There was a problem hiding this comment.
Instead of doing all this, how about changing port to uint16_t ?
marcalff
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
Please see comments for a simpler solution.
Done. I changed addListeningPort to use uint16_t as well. That keeps the types consistent, though I believe it still would not prevent silent wrapping at call sites when callers pass a wider integer type.
Fixes #4305
Changes
SocketAddr(u_long addr, int port)so ports below0or above65535are rejected instead of wrapping during theuint16_tconversion.HttpServer::addListeningPort(int port)to return-1for an invalid port before creating or binding a socket.-1,65536, and99999.Tested with:
CHANGELOG.mdupdated for non-trivial changes