Skip to content

urlapi: do not add the zone id twice to a set IPv6 host - #23586

Closed
Ar-maan05 wants to merge 1 commit into
curl:masterfrom
Ar-maan05:urlapi-host-zoneid-twice
Closed

Ar-maan05 wants to merge 1 commit into
curl:masterfrom
Ar-maan05:urlapi-host-zoneid-twice

Conversation

@Ar-maan05

Copy link
Copy Markdown
Contributor

Setting an IPv6 host with a zone id gives a URL with the zone in it twice:

curl_url_set(u, CURLUPART_URL, "https://example.com/", 0);
curl_url_set(u, CURLUPART_HOST, "[fe80::1%25eth0]", 0);
curl_url_get(u, CURLUPART_URL, &p, 0);
before: https://[fe80::1%25eth0%25eth0]/
after:  https://[fe80::1%25eth0]/

The output does not parse back. Without CURLU_URLENCODE, url_sethost() checks a decoded copy of the host. That check pulls the zone out into u->zoneid, but the original string with the zone still in it is what gets stored, and urlget_url() then appends u->zoneid again. This stores the checked address instead, so the host part is [fe80::1] with the zone kept separately, the same as when the whole URL is parsed. One side effect: the address is now normalized the way a parsed URL already is (for example [FE80::0:1] becomes [fe80::1]).

I added two set_parts cases to lib1560.c (the plain one fails before and passes after), and the URL and IPv6 tests still pass locally.

I found this with an AI-assisted code review and then checked it by hand on a local build.

Setting CURLUPART_HOST to "[fe80::1%25eth0]" without CURLU_URLENCODE
checked a decoded copy of the host, which moved the zone id into
u->zoneid, but then stored the original string with the zone still in
it. Getting CURLUPART_URL then appended the zone id again and returned
"[fe80::1%25eth0%25eth0]", which does not parse back.

Store the checked and normalized address instead, the same form a
parsed URL gets.

Extend test 1560 to verify.
@github-actions github-actions Bot added the tests label Oct 24, 2026

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.

🟢 Approval recommended

The localized fix preserves buffer ownership, separates the address from its zone ID, and includes regression coverage for both affected operations.

No open issues 🎉

What changed in this PR

This PR fixes duplicate IPv6 zone IDs when setting a host through the URL API, making host storage consistent with full-URL parsing.

Changes:

  • Store the validated, normalized IPv6 address separately from its zone ID.
  • Add regression cases for setting a host with a zone ID and then clearing the zone ID.
File Description
tests/​libtest/​lib1560.c Adds regression coverage for zone-ID handling when setting hosts.
lib/​urlapi.c Stores the normalized IPv6 host to prevent duplicate zone IDs.

Review effort: Balanced

@bagder bagder closed this in 350c430 Oct 24, 2026
@bagder

bagder commented Oct 24, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants