Re: [ANNOUNCE] GIT 1.5.4-rc3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jan 12, 2008 at 09:47:48AM +0200, Ismail Dönmez wrote:

> So looks like tests no longer work as root, so I run make test as normal user 
> and I now see t7300-clean.sh fail, this time a real failure:
> 
> Removing part3.c
> ./test-lib.sh: line 193: 19413 Aborted                 git-clean
> * FAIL 5: git-clean with prefix

I couldn't reproduce this just running the test, but running it under
valgrind showed a memory access error. Fix is below.

Junio, can you please sanity check this fix (it stops the valgrind
error, but I want to make sure my assumptions about match_pathspec are
right).

-- >8 --
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@xxxxxxxx>
---
It might be more readable to actually set a variable pathspec_size and
use that.

 builtin-clean.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin-clean.c b/builtin-clean.c
index 6cad8ea..eb853a3 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 {
-- 
1.5.4.rc3-dirty


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux