{"thread":{"id":"10726","subject":"[PATCH] send-pack: segfault fix on forced push","startedAt":"2007-11-08T09:38:12Z","lastAt":"2007-11-08T09:43:39Z","messageCount":2,"participants":["Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"58844","messageId":"7vsl3h2i2j.fsf@gitster.siamese.dyndns.org","threadId":"10726","inReplyTo":null,"subject":"[PATCH] send-pack: segfault fix on forced push","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-08T09:38:12Z","receivedAt":"2007-11-08T09:38:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When pushing to overwrite a ref that points at a commit we do\nnot even have, the recent \"terse push\" patch tried to get a\nunique abbreviation for the non-existent (from our point of\nview) object, which resulted in strcpy(buf, NULL) and\nsegfaulted.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-send-pack.c         |    5 +++--\n t/t5405-send-pack-rewind.sh |   42 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 45 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-send-pack.c b/builtin-send-pack.c\nindex c1fd3f5..5a0f5c6 100644\n--- a/builtin-send-pack.c\n+++ b/builtin-send-pack.c\n@@ -365,8 +365,9 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest\n \t\t\tchar quickref[83];\n \t\t\tchar type = ' ';\n \t\t\tconst char *msg = \"\";\n-\n-\t\t\tstrcpy(quickref, find_unique_abbrev(ref->old_sha1, DEFAULT_ABBREV));\n+\t\t\tconst char *old_abb;\n+\t\t\told_abb = find_unique_abbrev(ref->old_sha1, DEFAULT_ABBREV);\n+\t\t\tstrcpy(quickref, old_abb ? old_abb : old_hex);\n \t\t\tif (ref_newer(ref->peer_ref->new_sha1, ref->old_sha1))\n \t\t\t\tstrcat(quickref, \"..\");\n \t\t\telse {\ndiff --git a/t/t5405-send-pack-rewind.sh b/t/t5405-send-pack-rewind.sh\nnew file mode 100755\nindex 0000000..86abc62\n--- /dev/null\n+++ b/t/t5405-send-pack-rewind.sh\n@@ -0,0 +1,42 @@\n+#!/bin/sh\n+\n+test_description='forced push to replace commit we do not have'\n+\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\n+\t>file1 && git add file1 && test_tick &&\n+\tgit commit -m Initial &&\n+\n+\tmkdir another && (\n+\t\tcd another &&\n+\t\tgit init &&\n+\t\tgit fetch .. master:master\n+\t) &&\n+\n+\t>file2 && git add file2 && test_tick &&\n+\tgit commit -m Second\n+\n+'\n+\n+test_expect_success 'non forced push should die not segfault' '\n+\n+\t(\n+\t\tcd another &&\n+\t\tgit push .. master:master\n+\t\ttest $? = 1\n+\t)\n+\n+'\n+\n+test_expect_success 'forced push should succeed' '\n+\n+\t(\n+\t\tcd another &&\n+\t\tgit push .. +master:master\n+\t)\n+\n+'\n+\n+test_done\n"},{"id":"58845","messageId":"20071108094339.GA20766@sigill.intra.peff.net","threadId":"10726","inReplyTo":"7vsl3h2i2j.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] send-pack: segfault fix on forced push","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-11-08T09:43:39Z","receivedAt":"2007-11-08T09:43:39Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Nov 08, 2007 at 01:38:12AM -0800, Junio C Hamano wrote:\n\n> When pushing to overwrite a ref that points at a commit we do\n> not even have, the recent \"terse push\" patch tried to get a\n> unique abbreviation for the non-existent (from our point of\n> view) object, which resulted in strcpy(buf, NULL) and\n> segfaulted.\n\nGood catch. The fix looks obviously correct.\n\n-Peff\n"}]}