From a8db80c22494396a81d2b4b7f4082c369fc0f78d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 12 Jan 2008 04:04:32 -0500 Subject: [PATCH] git-clean: fix off-by-one memory access when given no arguments MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Tested-by: İsmail Dönmez Signed-off-by: Junio C Hamano --- builtin-clean.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin-clean.c b/builtin-clean.c index 6cad8eaf2..eb853a37c 100644 --- a/builtin-clean.c +++ b/builtin-clean.c @@ -90,7 +90,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) strbuf_init(&directory, 0); if (pathspec) - seen = xmalloc(argc); + seen = xmalloc(argc > 0 ? argc : 1); for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; @@ -125,7 +125,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) continue; if (pathspec) { - memset(seen, 0, argc); + memset(seen, 0, argc > 0 ? argc : 1); matches = match_pathspec(pathspec, ent->name, ent->len, baselen, seen); } else { -- 2.30.2