]> granicus.if.org Git - curl/commitdiff
fnmatch: do not match the empty string with a character set
authorPatrick Monnerat <patrick@monnerat.net>
Mon, 29 Jan 2018 12:01:43 +0000 (13:01 +0100)
committerPatrick Monnerat <patrick@monnerat.net>
Wed, 31 Jan 2018 00:17:35 +0000 (01:17 +0100)
lib/curl_fnmatch.c
tests/unit/unit1307.c

index f33bba1f1b868a1fd18282338c29b53eae4fe145..5b6d28c06389e4a792f6bb0cf8ce29ee820532b6 100644 (file)
@@ -352,6 +352,8 @@ static int loop(const unsigned char *pattern, const unsigned char *string,
         unsigned char *pp = p + 1; /* cannot handle with pointer to register */
         if(setcharset(&pp, charset)) {
           int found = FALSE;
+          if(!*s)
+            return CURL_FNMATCH_NOMATCH;
           if(charset[(unsigned int)*s])
             found = TRUE;
           else if(charset[CURLFNM_ALNUM])
@@ -380,9 +382,7 @@ static int loop(const unsigned char *pattern, const unsigned char *string,
 
           if(found) {
             p = pp + 1;
-            if(*s)
-              /* don't advance if we're matching on an empty string */
-              s++;
+            s++;
             memset(charset, 0, CURLFNM_CHSET_SIZE);
           }
           else
index 266eed3923fbbe3d4a6721423b798d4a82512492..eff5edebc8b97d3680af489825b038886470657b 100644 (file)
@@ -97,8 +97,8 @@ static const struct testcase tests[] = {
   { "*[^a].t?t",                "a.txt",                  NOMATCH },
   { "*[^a].t?t",                "ba.txt",                 NOMATCH },
   { "*[^a].t?t",                "ab.txt",                 MATCH },
-  { "*[^a]",                    "",                       MATCH },
-  { "[!ÿ]",                     "",                       MATCH },
+  { "*[^a]",                    "",                       NOMATCH },
+  { "[!ÿ]",                     "",                       NOMATCH },
   { "[!?*[]",                   "?",                      NOMATCH },
   { "[!!]",                     "!",                      NOMATCH },
   { "[!!]",                     "x",                      MATCH },