Skip to content

Commit 6a01554

Browse files
Clemens Buchachergitster
authored andcommitted
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 <[email protected]> Reported-by: Erik Faye-Lund <[email protected]> Acked-by: Jay Soffian <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e57cb01 commit 6a01554

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

builtin-remote.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ static int get_push_ref_states(const struct ref *remote_refs,
299299
return 0;
300300

301301
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);
306303

304+
push_tail = &push_map;
305+
while (*push_tail)
306+
push_tail = &((*push_tail)->next);
307307
match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr,
308308
remote->push_refspec, MATCH_REFS_NONE);
309309

t/t5505-remote.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,5 +494,15 @@ test_expect_success 'remote prune to cause a dangling symref' '
494494
grep "dangling symref" err
495495
'
496496

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+
497507
test_done
498508

0 commit comments

Comments
 (0)