summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2018-05-27 23:24:27 +0200
committerDaniel Stenberg <daniel@haxx.se>2018-05-28 20:01:08 +0200
commitd5469cdb051beda81f3d1cdd050286097cbd8106 (patch)
treeb375a6059a8915d3e439d2d9cbb5c1aad7fcd451
parenteb678badcb6783356a5160d91dc637701c919395 (diff)
downloadcurl-bagder/fnmatch-escaped-brackets.tar.gz
fnmatch: insist on escaped bracket to matchbagder/fnmatch-escaped-brackets
A non-escaped bracket ([) is for a character group - as documented. It will *not* match an individual bracket anymore. Test case 1307 updated accordingly to match. Problem detected by OSS-Fuzz, although this fix is probably not a final fix for the notorious timeout issues. Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8525
-rw-r--r--lib/curl_fnmatch.c4
-rw-r--r--tests/unit/unit1307.c17
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/curl_fnmatch.c b/lib/curl_fnmatch.c
index 268fe79b3..bd4e61f4e 100644
--- a/lib/curl_fnmatch.c
+++ b/lib/curl_fnmatch.c
@@ -334,9 +334,9 @@ static int loop(const unsigned char *pattern, const unsigned char *string,
s++;
break;
}
+ /* Syntax error in set; mismatch! */
+ return CURL_FNMATCH_NOMATCH;
- /* Syntax error in set: this must be taken as a regular character. */
- /* FALLTHROUGH */
default:
if(*p++ != *s++)
return CURL_FNMATCH_NOMATCH;
diff --git a/tests/unit/unit1307.c b/tests/unit/unit1307.c
index 5f60332b8..fe16ed324 100644
--- a/tests/unit/unit1307.c
+++ b/tests/unit/unit1307.c
@@ -34,9 +34,17 @@ struct testcase {
static const struct testcase tests[] = {
/* brackets syntax */
+ {"*[*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\001\177[[[[[[[[[[[[[[[[[[[[[",
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[",
+ NOMATCH},
+
{ "\\[", "[", MATCH },
- { "[", "[", MATCH },
- { "[]", "[]", MATCH },
+ { "[", "[", NOMATCH },
+ { "[]", "[]", NOMATCH },
{ "[][]", "[", MATCH },
{ "[][]", "]", MATCH },
{ "[[]", "[", MATCH },
@@ -230,8 +238,9 @@ UNITTEST_START
for(i = 0; i < testnum; i++) {
rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
if(rc != tests[i].result) {
- printf("Curl_fnmatch(\"%s\", \"%s\") should return %d (returns %d)\n",
- tests[i].pattern, tests[i].string, tests[i].result, rc);
+ printf("Curl_fnmatch(\"%s\", \"%s\") should return %d (returns %d)"
+ " [%d]\n",
+ tests[i].pattern, tests[i].string, tests[i].result, rc, i);
fail("pattern mismatch");
}
}