summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-12-01 14:36:22 -0500
committerRich Felker <dalias@aerifal.cx>2013-12-01 14:36:22 -0500
commit6ec82a3b58ee1b873ff0dfad8fa9d41c3d25dcc0 (patch)
tree0bcd19e8e3428bf9cb5ffa91ff9b12b21e526643 /src
parentda0fcdb8e913ca7cdf8931328f2b37e93309b2c5 (diff)
downloadmusl-6ec82a3b58ee1b873ff0dfad8fa9d41c3d25dcc0.tar.gz
fix fnmatch corner cases related to escaping
the FNM_PATHNAME logic for advancing by /-delimited components was incorrect when the / character was escaped (i.e. \/), and a final \ at the end of pattern was not handled correctly.
Diffstat (limited to 'src')
-rw-r--r--src/regex/fnmatch.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/regex/fnmatch.c b/src/regex/fnmatch.c
index c3fcaa5b..093eb1cc 100644
--- a/src/regex/fnmatch.c
+++ b/src/regex/fnmatch.c
@@ -19,7 +19,7 @@
#include <wchar.h>
#include <wctype.h>
-#define END -1
+#define END 0
#define UNMATCHABLE -2
#define BRACKET -3
#define QUESTION -4
@@ -53,7 +53,7 @@ static int pat_next(const char *pat, size_t m, size_t *step, int flags)
return END;
}
*step = 1;
- if (pat[0]=='\\' && !(flags & FNM_NOESCAPE)) {
+ if (pat[0]=='\\' && pat[1] && !(flags & FNM_NOESCAPE)) {
*step = 2;
pat++;
esc = 1;
@@ -288,12 +288,12 @@ int fnmatch(const char *pat, const char *str, int flags)
if (flags & FNM_PATHNAME) for (;;) {
for (s=str; *s && *s!='/'; s++);
for (p=pat; (c=pat_next(p, -1, &inc, flags))!=END && c!='/'; p+=inc);
- if (*p!=*s) return FNM_NOMATCH;
+ if (c!=*s) return FNM_NOMATCH;
if (fnmatch_internal(pat, p-pat, str, s-str, flags))
return FNM_NOMATCH;
if (!*s) return 0;
str = s+1;
- pat = p+1;
+ pat = p+inc;
}
return fnmatch_internal(pat, -1, str, -1, flags);
}