Skip to content

urlapi: normalize legacy numeric IPv4 hosts set via CURLUPART_HOST - #23027

Closed
bagder wants to merge 1 commit into
masterfrom
bagder/url-set-ipv4
Closed

bagder wants to merge 1 commit into
masterfrom
bagder/url-set-ipv4

Conversation

@bagder

@bagder bagder commented Sep 22, 2026

Copy link
Copy Markdown
Member

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

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
@github-actions github-actions Bot added the tests label Sep 22, 2026
@bagder
bagder requested a balanced review from Copilot September 22, 2026 06:18
@bagder
bagder marked this pull request as ready for review September 22, 2026 06:18

Copilot AI 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.

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 Medium severity · 1 Low severity

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.

Comment thread lib/urlapi.c
Comment thread tests/unit/unit1675.c
@bagder bagder closed this in 4be7143 Sep 22, 2026
@bagder
bagder deleted the bagder/url-set-ipv4 branch September 22, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants