Skip to content

fix: prevent false port parsing when host has no colon - #245

Open
jiuker wants to merge 6 commits into
minio:mainfrom
jiuker:rl-parse-port-without-colon
Open

fix: prevent false port parsing when host has no colon#245
jiuker wants to merge 6 commits into
minio:mainfrom
jiuker:rl-parse-port-without-colon

Conversation

@jiuker

@jiuker jiuker commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

When the host string contains no colon, std::getline(ss, portstr, ':') assigns the entire host to portstr, causing stoi to silently parse a bogus port number (e.g. "1.2.3.4" → port=1). Add a host.find(':') != npos guard so that port parsing only occurs when a colon is actually present.

fix #203

Summary by CodeRabbit

  • Bug Fixes
    • Improved URL parsing to extract port numbers only when a valid port separator and non-empty port value are present.
    • Prevented invalid or empty port values from being accepted.
    • Improved handling of URLs with and without explicitly specified ports across IPv4 addresses and hostnames.
    • Added validation to help ensure port values are interpreted consistently and accurately.

When the host string contains no colon, std::getline(ss, portstr, ':') assigns the entire host to portstr, causing stoi to silently parse a bogus port number (e.g. "1.2.3.4" → port=1). Add a host.find(':') != npos guard so that port parsing only occurs when a colon is actually present.
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jiuker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 831c5d1e-d4dd-4c64-8c14-601f195d3834

📥 Commits

Reviewing files that changed from the base of the PR and between cdc995e and a2684da.

📒 Files selected for processing (1)
  • tests/tests.cc
📝 Walkthrough

Walkthrough

The URL parser now parses a port only when the host contains a colon and the extracted port is nonempty. A regression test covers bare hosts and explicit port values.

Changes

URL port parsing

Layer / File(s) Summary
Guard URL port parsing
src/http.cc
Adds the <algorithm> include. Requires a colon and a nonempty port string before parsing the URL port.
Validate URL parsing
tests/tests.cc
Adds TestUrlParse() for bare and port-qualified hosts. Runs the test before environment validation and server-dependent tests.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: harshavardhana

Poem

A rabbit checks the URL path,
Finds no port without a colon’s mark.
Empty strings stay safely still,
The parser follows a clearer will.
Hop, hop—clean parsing in the dark!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the fix for incorrect port parsing when the host has no colon.
Linked Issues check ✅ Passed The implementation prevents port parsing without a host colon and adds regression coverage for bare and port-qualified hosts, satisfying issue #203.
Out of Scope Changes check ✅ Passed The source change and regression test directly support the URL port parsing fix described in issue #203.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

lint

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/http.cc`:
- Line 212: Add regression tests for the host/port parsing logic surrounding the
port guard in src/http.cc, covering bare IPv4 and hostname inputs returning the
original host with port 0, plus an IPv4 address with port 9000 returning the
split host and parsed port. Verify the results through the existing parsing API
used by request and endpoint handling.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f9f3889e-dba4-4714-bf92-fef54ebb8dfb

📥 Commits

Reviewing files that changed from the base of the PR and between 28ec286 and b098b29.

📒 Files selected for processing (1)
  • src/http.cc

Comment thread src/http.cc
added ut

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/tests.cc`:
- Around line 1572-1574: Wrap the TestUrlParse() invocation in main() with
handling for its std::runtime_error, print the failure message, and return
EXIT_FAILURE; preserve the existing success path and subsequent test execution
when no exception is thrown.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7257dbff-2330-456f-89ad-1bce354f6301

📥 Commits

Reviewing files that changed from the base of the PR and between b098b29 and f2ed80a.

📒 Files selected for processing (1)
  • tests/tests.cc

Comment thread tests/tests.cc Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/tests.cc`:
- Line 1558: Update the expected port in the test case for “10.0.0.1:9000” to
9000, keeping the host expectation unchanged so the corrected parser test passes
without triggering failure.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 57a96df9-b43f-4072-96c3-3d264522843c

📥 Commits

Reviewing files that changed from the base of the PR and between f2ed80a and cdc995e.

📒 Files selected for processing (1)
  • tests/tests.cc

Comment thread tests/tests.cc Outdated
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.

Url parse incorrect logic

1 participant