Skip to content

Commit 6c41e97

Browse files
carlosmngitster
authored andcommitted
branch: don't assume the merge filter ref exists
print_ref_list looks up the merge_filter_ref and assumes that a valid pointer is returned. When the object doesn't exist, it tries to dereference a NULL pointer. This can be the case when git branch --merged is given an argument that isn't a valid commit name. Check whether the lookup returns a NULL pointer and die with an error if it does. Add a test, while we're at it. Signed-off-by: Carlos Martín Nieto <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c524ceb commit 6c41e97

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

builtin/branch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
528528
if (merge_filter != NO_FILTER) {
529529
struct commit *filter;
530530
filter = lookup_commit_reference_gently(merge_filter_ref, 0);
531+
if (!filter)
532+
die("object '%s' does not point to a commit",
533+
sha1_to_hex(merge_filter_ref));
534+
531535
filter->object.flags |= UNINTERESTING;
532536
add_pending_object(&ref_list.revs,
533537
(struct object *) filter, "");

t/t3200-branch.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,4 +620,8 @@ test_expect_success 'use set-upstream on the current branch' '
620620
621621
'
622622

623+
test_expect_success '--merged catches invalid object names' '
624+
test_must_fail git branch --merged 0000000000000000000000000000000000000000
625+
'
626+
623627
test_done

0 commit comments

Comments
 (0)