@matheusbsbs / matheus-bagliano / commits / 6738c81942
Fork 0

send-pack: segfault fix on forced push

When pushing to overwrite a ref that points at a commit we do not even have, the recent "terse push" patch tried to get a unique abbreviation for the non-existent (from our point of view) object, which resulted in strcpy(buf, NULL) and segfaulted. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 8, 2007 at 01:38 UTC 6738c8194286fa0017f72cb57628dcae9ec07b27
2 files changed +45 -2
builtin-send-pack.c
+3 -2
@@ -365,8 +365,9 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
365 char quickref[83];
366 char type = ' ';
367 const char *msg = "";
368 -
369 - strcpy(quickref, find_unique_abbrev(ref->old_sha1, DEFAULT_ABBREV));
368 + const char *old_abb;
369 + old_abb = find_unique_abbrev(ref->old_sha1, DEFAULT_ABBREV);
370 + strcpy(quickref, old_abb ? old_abb : old_hex);
371 if (ref_newer(ref->peer_ref->new_sha1, ref->old_sha1))
372 strcat(quickref, "..");
373 else {
t/t5405-send-pack-rewind.sh new
+42
@@ -0,0 +1,42 @@
1 +#!/bin/sh
2 +
3 +test_description='forced push to replace commit we do not have'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 +
9 + >file1 && git add file1 && test_tick &&
10 + git commit -m Initial &&
11 +
12 + mkdir another && (
13 + cd another &&
14 + git init &&
15 + git fetch .. master:master
16 + ) &&
17 +
18 + >file2 && git add file2 && test_tick &&
19 + git commit -m Second
20 +
21 +'
22 +
23 +test_expect_success 'non forced push should die not segfault' '
24 +
25 + (
26 + cd another &&
27 + git push .. master:master
28 + test $? = 1
29 + )
30 +
31 +'
32 +
33 +test_expect_success 'forced push should succeed' '
34 +
35 + (
36 + cd another &&
37 + git push .. +master:master
38 + )
39 +
40 +'
41 +
42 +test_done