Skip to content

Commit bb9e15a

Browse files
Uwe ZeisbergerJunio C Hamano
authored andcommitted
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>
1 parent 4170af8 commit bb9e15a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

builtin-grep.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ static int pathspec_matches(const char **paths, const char *name)
2929
int matchlen = strlen(match);
3030
const char *cp, *meta;
3131

32-
if ((matchlen <= namelen) &&
33-
!strncmp(name, match, matchlen) &&
34-
(match[matchlen-1] == '/' ||
35-
name[matchlen] == '\0' || name[matchlen] == '/'))
32+
if (!matchlen ||
33+
((matchlen <= namelen) &&
34+
!strncmp(name, match, matchlen) &&
35+
(match[matchlen-1] == '/' ||
36+
name[matchlen] == '\0' || name[matchlen] == '/')))
3637
return 1;
3738
if (!fnmatch(match, name, 0))
3839
return 1;

0 commit comments

Comments
 (0)