Skip to content

Commit

Permalink
git-clean: fix off-by-one memory access when given no arguments
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 12, 2008
1 parent 98fa5b6 commit a8db80c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin-clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a8db80c

Please sign in to comment.