summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de>2006-06-21 11:04:12 +0200
committerLibravatar Junio C Hamano <junkio@cox.net>2006-06-21 02:30:46 -0700
commitbb9e15a83c425ff31e4da6b004bd4557d528b755 (patch)
tree1fd9cce933413556be5994202c7bead7222df370
parentcheckout -f: do not leave untracked working tree files. (diff)
downloadtgif-bb9e15a83c425ff31e4da6b004bd4557d528b755.tar.xz
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 <Uwe_Zeisberger@digi.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--builtin-grep.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/builtin-grep.c b/builtin-grep.c
index 9806499263..f7767bb4ee 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;