]> git.ipfire.org Git - thirdparty/git.git/commitdiff
list-objects.c: handle unexpected non-blob entries
authorTaylor Blau <me@ttaylorr.com>
Wed, 10 Apr 2019 02:13:17 +0000 (19:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Apr 2019 03:59:39 +0000 (12:59 +0900)
Fix one of the cases described in the previous commit where a tree-entry
that is promised to a blob is in fact a non-blob.

When 'lookup_blob()' returns NULL, it is because Git has cached the
requested object as a non-blob. In this case, prevent a SIGSEGV by
'die()'-ing immediately before attempting to dereference the result.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
list-objects.c
t/t6102-rev-list-unexpected-objects.sh

index dc77361e11d02a4eaa994f4351310a0d54d33ef6..ea04bbdee6a938d02d46fc400471a62a553da1a1 100644 (file)
@@ -133,6 +133,11 @@ static void process_tree_contents(struct traversal_context *ctx,
                                        base, entry.path);
                else {
                        struct blob *b = lookup_blob(ctx->revs->repo, &entry.oid);
+                       if (!b) {
+                               die(_("entry '%s' in tree %s has blob mode, "
+                                     "but is not a blob"),
+                                   entry.path, oid_to_hex(&tree->object.oid));
+                       }
                        b->object.flags |= NOT_USER_GIVEN;
                        process_blob(ctx, b, base, entry.path);
                }
index 15072ecce3360b43fc0ad414a881afc95cb2d40d..1377c603783f0807eea0482aa401589d84592c3b 100755 (executable)
@@ -20,8 +20,9 @@ test_expect_failure 'traverse unexpected non-blob entry (lone)' '
        test_must_fail git rev-list --objects $broken_tree
 '
 
-test_expect_failure 'traverse unexpected non-blob entry (seen)' '
-       test_must_fail git rev-list --objects $tree $broken_tree
+test_expect_success 'traverse unexpected non-blob entry (seen)' '
+       test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 &&
+       test_i18ngrep "is not a blob" output
 '
 
 test_expect_success 'setup unexpected non-tree entry' '