Skip to content

reject out-of-range port in SplitHostAndPort - #3434

Open
ubeddulla wants to merge 1 commit into
apache:masterfrom
ubeddulla:uri-out-of-range-port
Open

reject out-of-range port in SplitHostAndPort#3434
ubeddulla wants to merge 1 commit into
apache:masterfrom
ubeddulla:uri-out-of-range-port

Conversation

@ubeddulla

Copy link
Copy Markdown
Contributor

SplitHostAndPort parses the port from a URL or Host header by accumulating digits into a uint64 and narrowing the result with static_cast, with no range check, so a value above INT_MAX silently wraps to a valid-looking but wrong port (":4294967377" becomes 81) and a long run of digits overflows the accumulator. str2endpoint and hostname2endpoint already reject ports outside 0-65535, so this stops accumulating past the range and maps any out-of-range value to -1 to keep the URL parser consistent with them. The added regression test in brpc_uri_unittest.cpp covers the wraparound, the just-over-limit case, a very long digit run, and the Host header path.

Signed-off-by: ubeddulla khan <ubed@bugqore.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant