noproxy: fix ipv6 handling

Closes #19828
This commit is contained in:
Georg Schulz-Allgaier 2025-12-03 22:49:05 +01:00 committed by Daniel Stenberg
parent e8a4068e68
commit ff2aaed9ba
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 42 additions and 58 deletions

View File

@ -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) {

View File

@ -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},