Fix cloning (memory corruption)

upload-pack would set create_full_pack=1 if nr_has==0, but would ask later
if nr_needs<MAX_NEEDS. If that proves true, it would ignore create_full_pack,
and arguments would be written into unreserved memory.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Johannes Schindelin 2005-10-26 16:18:56 +02:00 committed by Junio C Hamano
parent 565ebbf79f
commit b5c367f75c

View File

@ -60,7 +60,7 @@ static void create_pack_file(void)
close(fd[1]); close(fd[1]);
*p++ = "git-rev-list"; *p++ = "git-rev-list";
*p++ = "--objects"; *p++ = "--objects";
if (MAX_NEEDS <= nr_needs) if (create_full_pack || MAX_NEEDS <= nr_needs)
*p++ = "--all"; *p++ = "--all";
else { else {
for (i = 0; i < nr_needs; i++) { for (i = 0; i < nr_needs; i++) {
@ -69,12 +69,13 @@ static void create_pack_file(void)
buf += 41; buf += 41;
} }
} }
for (i = 0; i < nr_has; i++) { if (!create_full_pack)
*p++ = buf; for (i = 0; i < nr_has; i++) {
*buf++ = '^'; *p++ = buf;
memcpy(buf, sha1_to_hex(has_sha1[i]), 41); *buf++ = '^';
buf += 41; memcpy(buf, sha1_to_hex(has_sha1[i]), 41);
} buf += 41;
}
*p++ = NULL; *p++ = NULL;
execvp("git-rev-list", argv); execvp("git-rev-list", argv);
die("git-upload-pack: unable to exec git-rev-list"); die("git-upload-pack: unable to exec git-rev-list");