Просмотр исходного кода

fix the end of string matching in fnmatch with FNM_PATHNAME

a '/' in the pattern could be incorrectly matched against the
terminating null byte in the string causing arbitrarily long
sequence of out-of-bounds access in fnmatch("/","",FNM_PATHNAME)
Szabolcs Nagy 11 лет назад
Родитель
Сommit
da0fcdb8e9
1 измененных файлов с 2 добавлено и 2 удалено
  1. 2 2
      src/regex/fnmatch.c

+ 2 - 2
src/regex/fnmatch.c

@@ -288,10 +288,10 @@ 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 (*s && *p!=*s) return FNM_NOMATCH;
+		if (*p!=*s) return FNM_NOMATCH;
 		if (fnmatch_internal(pat, p-pat, str, s-str, flags))
 			return FNM_NOMATCH;
-		if (!*s && c==END) return 0;
+		if (!*s) return 0;
 		str = s+1;
 		pat = p+1;
 	}