Skip to content

Commit

Permalink
branch: don't assume the merge filter ref exists
Browse files Browse the repository at this point in the history
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 <cmn@elego.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Carlos Martín Nieto authored and Junio C Hamano committed Feb 27, 2012
1 parent c524ceb commit 6c41e97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
if (merge_filter != NO_FILTER) {
struct commit *filter;
filter = lookup_commit_reference_gently(merge_filter_ref, 0);
if (!filter)
die("object '%s' does not point to a commit",
sha1_to_hex(merge_filter_ref));

filter->object.flags |= UNINTERESTING;
add_pending_object(&ref_list.revs,
(struct object *) filter, "");
Expand Down
4 changes: 4 additions & 0 deletions t/t3200-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -620,4 +620,8 @@ test_expect_success 'use set-upstream on the current branch' '
'

test_expect_success '--merged catches invalid object names' '
test_must_fail git branch --merged 0000000000000000000000000000000000000000
'

test_done

0 comments on commit 6c41e97

Please sign in to comment.