summaryrefslogtreecommitdiff
path: root/net-misc/curl/files/curl-7.86.0-proxy-noproxy-tailmatching.patch
blob: 15f5e64c91f3c33440d365fc58c9187546c4f7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
https://bugs.gentoo.org/878365#c2
https://github.com/curl/curl/issues/9821
https://github.com/curl/curl/commit/b830f9ba9e94acf672cd191993ff679fa888838b

From b830f9ba9e94acf672cd191993ff679fa888838b Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Fri, 28 Oct 2022 10:51:49 +0200
Subject: [PATCH] noproxy: fix tail-matching

Also ignore trailing dots in both host name and comparison pattern.

Regression in 7.86.0 (from 1e9a538e05c0)

Extended test 1614 to verify better.

Reported-by: Henning Schild
Fixes #9821
Closes #9822
--- a/lib/noproxy.c
+++ b/lib/noproxy.c
@@ -153,9 +153,14 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy)
     }
     else {
       unsigned int address;
+      namelen = strlen(name);
       if(1 == Curl_inet_pton(AF_INET, name, &address))
         type = TYPE_IPV4;
-      namelen = strlen(name);
+      else {
+        /* ignore trailing dots in the host name */
+        if(name[namelen - 1] == '.')
+          namelen--;
+      }
     }
 
     while(*p) {
@@ -177,12 +182,23 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy)
       if(tokenlen) {
         switch(type) {
         case TYPE_HOST:
-          if(*token == '.') {
-            ++token;
-            --tokenlen;
-            /* tailmatch */
-            match = (tokenlen <= namelen) &&
-              strncasecompare(token, name + (namelen - tokenlen), namelen);
+          /* ignore trailing dots in the token to check */
+          if(token[tokenlen - 1] == '.')
+            tokenlen--;
+
+          if(tokenlen && (*token == '.')) {
+            /* A: example.com matches '.example.com'
+               B: www.example.com matches '.example.com'
+               C: nonexample.com DOES NOT match '.example.com'
+            */
+            if((tokenlen - 1) == namelen)
+              /* case A, exact match without leading dot */
+              match = strncasecompare(token + 1, name, namelen);
+            else if(tokenlen < namelen)
+              /* case B, tailmatch with leading dot */
+              match = strncasecompare(token, name + (namelen - tokenlen),
+                                      tokenlen);
+            /* case C passes through, not a match */
           }
           else
             match = (tokenlen == namelen) &&