]> granicus.if.org Git - git/commitdiff
setup.c: stop prefix_pathspec() from looping past the end of string
authorAndrew Wong <andrew.kw.w@gmail.com>
Thu, 7 Mar 2013 16:36:03 +0000 (11:36 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Mar 2013 16:39:09 +0000 (09:39 -0700)
The code assumes that the string ends at either `)` or `,`, and does
not handle the case where strcspn() returns length due to end of
string.  So specifying ":(top" as pathspec will cause the loop to go
past the end of string.

Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c

diff --git a/setup.c b/setup.c
index 3a1b2fd45580cad7ecd55efa755872efc81075ad..e61458a7d05497dc83d7b64448980f483a593211 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -199,10 +199,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] == ')')
-                               nextat = copyfrom + len;
-                       else
+                       if (copyfrom[len] == ',')
                                nextat = copyfrom + len + 1;
+                       else
+                               /* handle ')' and '\0' */
+                               nextat = copyfrom + len;
                        if (!len)
                                continue;
                        for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)