Repository navigation
Conversation
url_sethost() only ran hostname_check6()/hostname_check() on a value set through curl_url_set(CURLUPART_HOST, ...), unlike parse_authority() which also calls ipv4_normalize() when parsing a full URL. This let legacy numeric IPv4 spellings (e.g. "2130706433", "0177.1", "0x7f.1") pass through CURLUPART_HOST unchanged, while the same input parsed as part of a full URL gets normalized to dotted decimal. Applications that inspect the host via the URL API before connecting could see a different address than what the system resolver later resolves for these forms, since resolvers such as glibc's getaddrinfo() do recognize them. Make url_sethost() call ipv4_normalize() on the host as well, so CURLUPART_HOST produces the same canonical result as the full URL parser, regardless of which API path set the host. The destination dynbuf is sized as (nalloc*3)+1+leadingslash, a cap meant to bound percent-encoding growth. ipv4_normalize() can expand a short legacy-numeric host (e.g. "0" -> "0.0.0.0") past that 3x bound, so for CURLUPART_HOST ensure the initial capacity is at least 16 bytes, enough for the longest possible dotted-decimal result plus NUL. Reported-by: Joshua Rogers
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The temporary dynbuf rejects hostnames exactly at the documented input-size boundary, and one normalization branch lacks coverage.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Normalizes legacy numeric IPv4 hosts set through CURLUPART_HOST to match full-URL parsing.
Changes:
- Adds IPv4 normalization and buffer sizing.
- Adds parity tests and updates existing expectations.
- Documents canonicalization behavior.
| File | Description |
|---|---|
lib/urlapi.c |
Normalizes directly set hosts. |
tests/unit/unit1675.c |
Adds normalization parity tests. |
tests/libtest/lib1560.c |
Updates expected normalized URL. |
docs/libcurl/curl_url_set.md |
Documents numeric IPv4 normalization. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


url_sethost() only ran hostname_check6()/hostname_check() on a value set through curl_url_set(CURLUPART_HOST, ...), unlike parse_authority() which also calls ipv4_normalize() when parsing a full URL. This let legacy numeric IPv4 spellings (e.g. "2130706433", "0177.1", "0x7f.1") pass through CURLUPART_HOST unchanged, while the same input parsed as part of a full URL gets normalized to dotted decimal. Applications that inspect the host via the URL API before connecting could see a different address than what the system resolver later resolves for these forms, since resolvers such as glibc's getaddrinfo() do recognize them.
Make url_sethost() call ipv4_normalize() on the host as well, so CURLUPART_HOST produces the same canonical result as the full URL parser, regardless of which API path set the host.
The destination dynbuf is sized as (nalloc*3)+1+leadingslash, a cap meant to bound percent-encoding growth. ipv4_normalize() can expand a short legacy-numeric host (e.g. "0" -> "0.0.0.0") past that 3x bound, so for CURLUPART_HOST ensure the initial capacity is at least 16 bytes, enough for the longest possible dotted-decimal result plus NUL.
Reported-by: Joshua Rogers