]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
noproxy: fix ipv6 handling
authorGeorg Schulz-Allgaier <georg_schulz-allgaier@genua.de>
Wed, 3 Dec 2025 21:49:05 +0000 (22:49 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 4 Dec 2025 11:16:02 +0000 (12:16 +0100)
Closes #19828

lib/noproxy.c
tests/unit/unit1614.c

index 569466fb62ecb8d7f73323fdd16d6dfb01c70541..e0d0877fdc4ff54437be836c4ec9c9299a993bd9 100644 (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) {
index 675133e5adf6ea7b6cf6073590793283ff7dc287..7b66af8431199b8326e7b288d7c3655df2131c7f 100644 (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},