git-clean: fix off-by-one memory access when given no arguments
The "seen" variable is used by match_pathspec, and must have as many elements as there are in the given pathspec. We create the pathspec either from the command line arguments _or_ from just the current prefix. Thus allocating "seen" based upon just argc is wrong, since if argc == 0, then we still have one pathspec, the prefix, but we don't allocate any space in "seen". Signed-off-by: Jeff King <peff@peff.net> Tested-by: İsmail Dönmez <ismail@pardus.org.tr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 12, 2008 at 04:04 UTC
a8db80c22494396a81d2b4b7f4082c369fc0f78d
1 file changed
+2
-2
builtin-clean.c
+2
-2
@@ -90,7 +90,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
90
strbuf_init(&directory, 0);
91
92
if (pathspec)
93
- seen = xmalloc(argc);
93
+ seen = xmalloc(argc > 0 ? argc : 1);
94
95
for (i = 0; i < dir.nr; i++) {
96
struct dir_entry *ent = dir.entries[i];
@@ -125,7 +125,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
125
continue;
126
127
if (pathspec) {
128
- memset(seen, 0, argc);
128
+ memset(seen, 0, argc > 0 ? argc : 1);
129
matches = match_pathspec(pathspec, ent->name, ent->len,
130
baselen, seen);
131
} else {