]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
noproxy: also match with adjacent comma
authorDaniel Stenberg <daniel@haxx.se>
Thu, 27 Oct 2022 11:54:27 +0000 (13:54 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 27 Oct 2022 21:31:31 +0000 (23:31 +0200)
If the host name is an IP address and the noproxy string contained that
IP address with a following comma, it would erroneously not match.

Extended test 1614 to verify this combo as well.

Reported-by: Henning Schild
Fixes #9813
Closes #9814

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

index 3409dab6f6eda88e85ecf97d69f693e4093fe3fd..58bc69a2dc15447c970a9ba4abe15fd67dff71e9 100644 (file)
@@ -192,18 +192,22 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy)
           /* FALLTHROUGH */
         case TYPE_IPV6: {
           const char *check = token;
-          char *slash = strchr(check, '/');
+          char *slash;
           unsigned int bits = 0;
           char checkip[128];
+          if(tokenlen >= sizeof(checkip))
+            /* this cannot match */
+            break;
+          /* copy the check name to a temp buffer */
+          memcpy(checkip, check, tokenlen);
+          checkip[tokenlen] = 0;
+          check = checkip;
+
+          slash = strchr(check, '/');
           /* if the slash is part of this token, use it */
-          if(slash && (slash < &check[tokenlen])) {
+          if(slash) {
             bits = atoi(slash + 1);
-            /* copy the check name to a temp buffer */
-            if(tokenlen >= sizeof(checkip))
-              break;
-            memcpy(checkip, check, tokenlen);
-            checkip[ slash - check ] = 0;
-            check = checkip;
+            *slash = 0; /* null terminate there */
           }
           if(type == TYPE_IPV6)
             match = Curl_cidr6_match(name, check, bits);
index 4a9d54eb620e189e6dea57b685e2ddf431b9365e..73bdbb4e007b31060f196416236d4432df21065f 100644 (file)
@@ -16,7 +16,7 @@ unittest
 proxy
 </features>
  <name>
-cidr comparisons
+noproxy and cidr comparisons
  </name>
 </client>
 <errorcode>
index 60285450c3cc384c77d18b34d32f98a9de1df0df..c2f563a0dc1d3cb861b1e337fd7aa32b5359372d 100644 (file)
@@ -77,6 +77,20 @@ UNITTEST_START
     { NULL, NULL, 0, FALSE} /* end marker */
   };
   struct noproxy list[]= {
+    { "127.0.0.1", "127.0.0.1,localhost", TRUE},
+    { "127.0.0.1", "127.0.0.1,localhost,", TRUE},
+    { "127.0.0.1", "127.0.0.1/8,localhost,", TRUE},
+    { "127.0.0.1", "127.0.0.1/28,localhost,", TRUE},
+    { "127.0.0.1", "127.0.0.1/31,localhost,", TRUE},
+    { "127.0.0.1", "localhost,127.0.0.1", TRUE},
+    { "127.0.0.1", "localhost,127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1."
+      "127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127."
+      "0.0.1.127.0.0.1.127.0.0." /* 128 bytes "address" */, FALSE},
+    { "127.0.0.1", "localhost,127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1."
+      "127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127."
+      "0.0.1.127.0.0.1.127.0.0" /* 127 bytes "address" */, FALSE},
+    { "localhost", "localhost,127.0.0.1", TRUE},
+    { "localhost", "127.0.0.1,localhost", TRUE},
     { "foobar", "barfoo", FALSE},
     { "foobar", "foobar", TRUE},
     { "192.168.0.1", "foobar", FALSE},