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

[PATCH] setup.c: Fix prefix_pathspec from looping pass end of string

From
Andrew Wong <andrew.kw.w@gmail.com>
Date
Mar 7, 2013, 16:36 UTC
Message-ID
<1362674163-24682-1-git-send-email-andrew.kw.w@gmail.com>

The previous code was assuming length ends at either `)` or `,`, and was not handling the case where strcspn returns length due to end of string. So specifying ":(top" as pathspec will cause the loop to go pass the end of string.

Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
---
 setup.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/setup.c b/setup.c
index 1dee47e..f4c4e73 100644
--- a/setup.c
+++ b/setup.c
@@ -207,9 +207,11 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
 		     *copyfrom && *copyfrom != ')';
 		     copyfrom = nextat) {
 			size_t len = strcspn(copyfrom, ",)");
-			if (copyfrom[len] == ')')
+			if (copyfrom[len] == '\0')
 				nextat = copyfrom + len;
-			else
+			else if (copyfrom[len] == ')')
+				nextat = copyfrom + len;
+			else if (copyfrom[len] == ',')
 				nextat = copyfrom + len + 1;
 			if (!len)
 				continue;
-- 
1.8.2.rc0.22.gb3600c3
Next: Junio C Hamano
Message 1 of 9 in “setup.c: Fix prefix_pathspec from looping pass end of string”
  1. setup.c: Fix prefix_pathspec from looping pass end of stringAndrew Wong, Mar 7, 2013
  2. Junio C HamanoMar 7, 2013
  3. Andrew WongMar 7, 2013
  4. Junio C HamanoMar 7, 2013
  5. Andrew WongMar 8, 2013
  6. Junio C HamanoMar 8, 2013
  7. Andrew WongMar 8, 2013
  8. 1/2 setup.c: Fix prefix_pathspec from looping pass end of stringAndrew Wong, Mar 9, 2013
  9. 2/2 setup.c: Check that the pathspec magic ends with ")"Andrew Wong, Mar 9, 2013

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.