From: Carlos Martín Nieto Date: Mon, 27 Feb 2012 15:11:53 +0000 (+0100) Subject: branch: don't assume the merge filter ref exists X-Git-Tag: v1.7.9.3~5^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6c41e97557d94df7085e3c0cff247305c9401968;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/branch.c b/builtin/branch.c index df908ed8f..d6691af0a 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -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, ""); diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 76903323a..6ad1763fd 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -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