@matheusbsbs / matheus-bagliano / commits / 6a01554e63
Fork 0

fix segfault showing an empty remote

In case of an empty list, the search for its tail caused a NULL-pointer dereference. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Reported-by: Erik Faye-Lund <kusmabite@googlemail.com> Acked-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed May 27, 2009 at 22:13 UTC 6a01554e6350123c78de805d820e90f1c56e5fdc
2 files changed +14 -4
builtin-remote.c
+4 -4
@@ -299,11 +299,11 @@ static int get_push_ref_states(const struct ref *remote_refs,
299 return 0;
300
301 local_refs = get_local_heads();
302 - ref = push_map = copy_ref_list(remote_refs);
303 - while (ref->next)
304 - ref = ref->next;
305 - push_tail = &ref->next;
302 + push_map = copy_ref_list(remote_refs);
303
304 + push_tail = &push_map;
305 + while (*push_tail)
306 + push_tail = &((*push_tail)->next);
307 match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr,
308 remote->push_refspec, MATCH_REFS_NONE);
309
t/t5505-remote.sh
+10
@@ -494,5 +494,15 @@ test_expect_success 'remote prune to cause a dangling symref' '
494 grep "dangling symref" err
495 '
496
497 +test_expect_success 'show empty remote' '
498 +
499 + test_create_repo empty &&
500 + git clone empty empty-clone &&
501 + (
502 + cd empty-clone &&
503 + git remote show origin
504 + )
505 +'
506 +
507 test_done
508