From: Uwe Zeisberger Date: Wed, 21 Jun 2006 09:04:12 +0000 (+0200) Subject: Fix possible out-of-bounds array access X-Git-Tag: v1.4.1-rc1~3^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bb9e15a83c425ff31e4da6b004bd4557d528b755;p=git.git Fix possible out-of-bounds array access If match is "", match[-1] is accessed. Let pathspec_matches return 1 in that case indicating that "" matches everything. Incidently this fixes git-grep'ing in ".". Signed-off-by: Uwe Zeisberger Signed-off-by: Junio C Hamano --- diff --git a/builtin-grep.c b/builtin-grep.c index 980649926..f7767bb4e 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -29,10 +29,11 @@ static int pathspec_matches(const char **paths, const char *name) int matchlen = strlen(match); const char *cp, *meta; - if ((matchlen <= namelen) && - !strncmp(name, match, matchlen) && - (match[matchlen-1] == '/' || - name[matchlen] == '\0' || name[matchlen] == '/')) + if (!matchlen || + ((matchlen <= namelen) && + !strncmp(name, match, matchlen) && + (match[matchlen-1] == '/' || + name[matchlen] == '\0' || name[matchlen] == '/'))) return 1; if (!fnmatch(match, name, 0)) return 1;