From: Georg Schulz-Allgaier Date: Wed, 3 Dec 2025 21:49:05 +0000 (+0100) Subject: noproxy: fix ipv6 handling X-Git-Tag: rc-8_18_0-1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff2aaed9ba6f186feb57f89fc68546759fdb6dad;p=thirdparty%2Fcurl.git noproxy: fix ipv6 handling Closes #19828 --- diff --git a/lib/noproxy.c b/lib/noproxy.c index 569466fb62..e0d0877fdc 100644 --- a/lib/noproxy.c +++ b/lib/noproxy.c @@ -185,8 +185,6 @@ static bool match_ip(int type, const char *token, size_t tokenlen, ****************************************************************/ bool Curl_check_noproxy(const char *name, const char *no_proxy) { - char hostip[128]; - /* * If we do not have a hostname at all, like for example with a FILE * transfer, we have nothing to interrogate the noproxy list with. @@ -202,37 +200,23 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy) if(no_proxy && no_proxy[0]) { const char *p = no_proxy; size_t namelen; + char address[16]; enum nametype type = TYPE_HOST; if(!strcmp("*", no_proxy)) return TRUE; /* NO_PROXY was specified and it was not just an asterisk */ - if(name[0] == '[') { - char *endptr; - /* IPv6 numerical address */ - endptr = strchr(name, ']'); - if(!endptr) - return FALSE; - name++; - namelen = endptr - name; - if(namelen >= sizeof(hostip)) - return FALSE; - memcpy(hostip, name, namelen); - hostip[namelen] = 0; - name = hostip; + /* Check if name is an IP address; if not, assume it being a hostname. */ + namelen = strlen(name); + if(curlx_inet_pton(AF_INET, name, &address) == 1) + type = TYPE_IPV4; + else if(curlx_inet_pton(AF_INET6, name, &address) == 1) type = TYPE_IPV6; - } else { - unsigned int address; - namelen = strlen(name); - if(curlx_inet_pton(AF_INET, name, &address) == 1) - type = TYPE_IPV4; - else { - /* ignore trailing dots in the hostname */ - if(name[namelen - 1] == '.') - namelen--; - } + /* ignore trailing dots in the hostname */ + if(name[namelen - 1] == '.') + namelen--; } while(*p) { diff --git a/tests/unit/unit1614.c b/tests/unit/unit1614.c index 675133e5ad..7b66af8431 100644 --- a/tests/unit/unit1614.c +++ b/tests/unit/unit1614.c @@ -113,39 +113,39 @@ static CURLcode test_unit1614(const char *arg) { "192.168.1.1", "foo, bar, 192.168.0.0/24", FALSE}, { "192.168.1.1", "foo, bar, 192.168.0.0/16", TRUE}, #ifdef USE_IPV6 - { "[::1]", "foo, bar, 192.168.0.0/16", FALSE}, - { "[::1]", "foo, bar, ::1/64", TRUE}, - { "[::1]", "::1/64", TRUE}, - { "[::1]", "::1/96", TRUE}, - { "[::1]", "::1/129", FALSE}, - { "[::1]", "::1/128", TRUE}, - { "[::1]", "::1/127", TRUE}, - { "[::1]", "::1/a127", FALSE}, - { "[::1]", "::1/127a", FALSE}, - { "[::1]", "::1/ 127", FALSE}, - { "[::1]", "::1/127 ", TRUE}, - { "[::1]", "::1/126", TRUE}, - { "[::1]", "::1/125", TRUE}, - { "[::1]", "::1/124", TRUE}, - { "[::1]", "::1/123", TRUE}, - { "[::1]", "::1/122", TRUE}, - { "[2001:db8:8000::1]", "2001:db8::/65", FALSE}, - { "[2001:db8:8000::1]", "2001:db8::/66", FALSE}, - { "[2001:db8:8000::1]", "2001:db8::/67", FALSE}, - { "[2001:db8:8000::1]", "2001:db8::/68", FALSE}, - { "[2001:db8:8000::1]", "2001:db8::/69", FALSE}, - { "[2001:db8:8000::1]", "2001:db8::/70", FALSE}, - { "[2001:db8:8000::1]", "2001:db8::/71", FALSE}, - { "[2001:db8:8000::1]", "2001:db8::/72", FALSE}, - { "[2001:db8::1]", "2001:db8::/65", TRUE}, - { "[2001:db8::1]", "2001:db8::/66", TRUE}, - { "[2001:db8::1]", "2001:db8::/67", TRUE}, - { "[2001:db8::1]", "2001:db8::/68", TRUE}, - { "[2001:db8::1]", "2001:db8::/69", TRUE}, - { "[2001:db8::1]", "2001:db8::/70", TRUE}, - { "[2001:db8::1]", "2001:db8::/71", TRUE}, - { "[2001:db8::1]", "2001:db8::/72", TRUE}, - { "[::1]", "::1/129", FALSE}, + { "::1", "foo, bar, 192.168.0.0/16", FALSE}, + { "::1", "foo, bar, ::1/64", TRUE}, + { "::1", "::1/64", TRUE}, + { "::1", "::1/96", TRUE}, + { "::1", "::1/129", FALSE}, + { "::1", "::1/128", TRUE}, + { "::1", "::1/127", TRUE}, + { "::1", "::1/a127", FALSE}, + { "::1", "::1/127a", FALSE}, + { "::1", "::1/ 127", FALSE}, + { "::1", "::1/127 ", TRUE}, + { "::1", "::1/126", TRUE}, + { "::1", "::1/125", TRUE}, + { "::1", "::1/124", TRUE}, + { "::1", "::1/123", TRUE}, + { "::1", "::1/122", TRUE}, + { "2001:db8:8000::1", "2001:db8::/65", FALSE}, + { "2001:db8:8000::1", "2001:db8::/66", FALSE}, + { "2001:db8:8000::1", "2001:db8::/67", FALSE}, + { "2001:db8:8000::1", "2001:db8::/68", FALSE}, + { "2001:db8:8000::1", "2001:db8::/69", FALSE}, + { "2001:db8:8000::1", "2001:db8::/70", FALSE}, + { "2001:db8:8000::1", "2001:db8::/71", FALSE}, + { "2001:db8:8000::1", "2001:db8::/72", FALSE}, + { "2001:db8::1", "2001:db8::/65", TRUE}, + { "2001:db8::1", "2001:db8::/66", TRUE}, + { "2001:db8::1", "2001:db8::/67", TRUE}, + { "2001:db8::1", "2001:db8::/68", TRUE}, + { "2001:db8::1", "2001:db8::/69", TRUE}, + { "2001:db8::1", "2001:db8::/70", TRUE}, + { "2001:db8::1", "2001:db8::/71", TRUE}, + { "2001:db8::1", "2001:db8::/72", TRUE}, + { "::1", "::1/129", FALSE}, { "bar", "foo, bar, ::1/64", TRUE}, { "BAr", "foo, bar, ::1/64", TRUE}, { "BAr", "foo,,,,, bar, ::1/64", TRUE},