git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix possible out-of-bounds array access

From
Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de>
Date
Jun 21, 2006, 09:04 UTC
Message-ID
<20060621090412.GA9267@informatik.uni-freiburg.de>
In-Reply-To
<20060620160836.GA20153@informatik.uni-freiburg.de>

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>
---
 builtin-grep.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c
index 9806499..f7767bb 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -29,10 +29,11 @@ static int pathspec_matches(const char *
 		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;
-- 
1.4.0

-- 
Uwe Zeisberger

http://www.google.com/search?q=12+mol+in+dozen
Previous: Uwe ZeisbergerNext: Junio C Hamano
Message 2 of 3 in “git grep in .”
  1. Uwe ZeisbergerJun 20, 2006
  2. Fix possible out-of-bounds array accessUwe Zeisberger, Jun 21, 2006
  3. Junio C HamanoJun 21, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.