Skip to content

Commit

Permalink
Fix possible out-of-bounds array access
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Uwe Zeisberger authored and Junio C Hamano committed Jun 21, 2006
1 parent 4170af8 commit bb9e15a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bb9e15a

Please sign in to comment.