{"thread":{"id":"2236","subject":"[PATCH] Fix cloning (memory corruption)","startedAt":"2005-10-26T14:18:56Z","lastAt":"2005-10-26T20:08:43Z","messageCount":2,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"10658","messageId":"Pine.LNX.4.63.0510261616550.21073@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2236","inReplyTo":null,"subject":"[PATCH] Fix cloning (memory corruption)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-26T14:18:56Z","receivedAt":"2005-10-26T14:18:56Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"upload-pack would set create_full_pack=1 if nr_has==0, but would ask later\nif nr_needs<MAX_NEEDS. If that proves true, it would ignore create_full_pack,\nand arguments would be written into unreserved memory.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tThis patch fixes what can be seen in all beauty when executing\n\n\t\tgit-clone . some_dir\n\n\tin a repository with lots of branches/tags.\n\n upload-pack.c |   15 ++++++++-------\n 1 files changed, 8 insertions(+), 7 deletions(-)\n\napplies-to: 764f8a201d063a7b49b07daa3a6e48b0af267162\nd05392d3ddfa647552190b73505a738330e492b4\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 07c1505..878254d 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -60,7 +60,7 @@ static void create_pack_file(void)\n \t\tclose(fd[1]);\n \t\t*p++ = \"git-rev-list\";\n \t\t*p++ = \"--objects\";\n-\t\tif (MAX_NEEDS <= nr_needs)\n+\t\tif (create_full_pack || MAX_NEEDS <= nr_needs)\n \t\t\t*p++ = \"--all\";\n \t\telse {\n \t\t\tfor (i = 0; i < nr_needs; i++) {\n@@ -69,12 +69,13 @@ static void create_pack_file(void)\n \t\t\t\tbuf += 41;\n \t\t\t}\n \t\t}\n-\t\tfor (i = 0; i < nr_has; i++) {\n-\t\t\t*p++ = buf;\n-\t\t\t*buf++ = '^';\n-\t\t\tmemcpy(buf, sha1_to_hex(has_sha1[i]), 41);\n-\t\t\tbuf += 41;\n-\t\t}\n+\t\tif (!create_full_pack)\n+\t\t\tfor (i = 0; i < nr_has; i++) {\n+\t\t\t\t*p++ = buf;\n+\t\t\t\t*buf++ = '^';\n+\t\t\t\tmemcpy(buf, sha1_to_hex(has_sha1[i]), 41);\n+\t\t\t\tbuf += 41;\n+\t\t\t}\n \t\t*p++ = NULL;\n \t\texecvp(\"git-rev-list\", argv);\n \t\tdie(\"git-upload-pack: unable to exec git-rev-list\");\n---\n0.99.8.GIT\n"},{"id":"10682","messageId":"7vmzkwca7o.fsf@assigned-by-dhcp.cox.net","threadId":"2236","inReplyTo":"Pine.LNX.4.63.0510261616550.21073@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Fix cloning (memory corruption)","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-10-26T20:08:43Z","receivedAt":"2005-10-26T20:08:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> upload-pack would set create_full_pack=1 if nr_has==0, but would ask later\n> if nr_needs<MAX_NEEDS. If that proves true, it would ignore create_full_pack,\n> and arguments would be written into unreserved memory.\n\nThanks.\n"}]}