Skip to content

Commit c685450

Browse files
peffgitster
authored andcommitted
ref-filter: fix NULL check for parse object failure
After we run parse_object_buffer() to get an object's contents, we try to check that the return value wasn't NULL. However, since our "struct object" is a pointer-to-pointer, and we assign like: *obj = parse_object_buffer(...); it's not correct to check: if (!obj) That will always be true, since our double pointer will continue to point to the single pointer (which is itself NULL). This is a regression that was introduced by aa46a0d (ref-filter: use oid_object_info() to get object, 2018-07-17); since that commit we'll segfault on a parse failure, as we try to look at the NULL object pointer. There are many ways a parse could fail, but most of them are hard to set up in the tests (it's easy to make a bogus object, but update-ref will refuse to point to it). The test here uses a tag which points to a wrong object type. A parse of just the broken tag object will succeed, but seeing both tag objects in the same process will lead to a parse error (since we'll see the pointed-to object as both types). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0628636 commit c685450

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
15951595

15961596
if (oi->info.contentp) {
15971597
*obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten);
1598-
if (!obj) {
1598+
if (!*obj) {
15991599
if (!eaten)
16001600
free(oi->content);
16011601
return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),

t/t6300-for-each-ref.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,4 +1030,14 @@ test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
10301030
test_cmp expect actual
10311031
'
10321032

1033+
test_expect_success 'for-each-ref reports broken tags' '
1034+
git tag -m "good tag" broken-tag-good HEAD &&
1035+
git cat-file tag broken-tag-good >good &&
1036+
sed s/commit/blob/ <good >bad &&
1037+
bad=$(git hash-object -w -t tag bad) &&
1038+
git update-ref refs/tags/broken-tag-bad $bad &&
1039+
test_must_fail git for-each-ref --format="%(*objectname)" \
1040+
refs/tags/broken-tag-*
1041+
'
1042+
10331043
test_done

0 commit comments

Comments
 (0)