list-objects.c: don't segfault for missing cmdline objects
authorMatthew DeVore <matvore@google.com>
Wed, 5 Dec 2018 21:43:46 +0000 (13:43 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 Dec 2018 01:10:13 +0000 (10:10 +0900)
When a command is invoked with both --exclude-promisor-objects,
--objects-edge-aggressive, and a missing object on the command line,
the rev_info.cmdline array could get a NULL pointer for the value of
an 'item' field. Prevent dereferencing of a NULL pointer in that
situation.

Properly handle --ignore-missing. If it is not passed, die when an
object is missing. Otherwise, just silently ignore it.

Signed-off-by: Matthew DeVore <matvore@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
t/t0410-partial-clone.sh
index b5108b75abc9ff0ef0438f4cba2e932e935ff94f..07dc0e28b60ce0072a53fcfd86061016f5708bdd 100644 (file)
@@ -1717,6 +1717,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
        if (!cant_be_filename)
                verify_non_filename(revs->prefix, arg);
        object = get_reference(revs, arg, &oid, flags ^ local_flags);
+       if (!object)
+               return revs->ignore_missing ? 0 : -1;
        add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags);
        add_pending_object_with_path(revs, object, arg, oc.mode, oc.path);
        free(oc.path);
index c521d7d6c61f3e3c76d5c4d51440ae114004a362..d446021bab237df9ad5403e5bdc61fc35cb7dbb9 100755 (executable)
@@ -304,7 +304,7 @@ test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob
        grep $(git -C repo rev-parse bar) out  # sanity check that some walking was done
 '
 
-test_expect_success 'rev-list accepts missing and promised objects on command line' '
+test_expect_success 'rev-list dies for missing objects on cmd line' '
        rm -rf repo &&
        test_create_repo repo &&
        test_commit -C repo foo &&
@@ -321,7 +321,19 @@ test_expect_success 'rev-list accepts missing and promised objects on command li
 
        git -C repo config core.repositoryformatversion 1 &&
        git -C repo config extensions.partialclone "arbitrary string" &&
-       git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" "$TREE" "$BLOB"
+
+       for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
+               test_must_fail git -C repo rev-list --objects \
+                       --exclude-promisor-objects "$OBJ" &&
+               test_must_fail git -C repo rev-list --objects-edge-aggressive \
+                       --exclude-promisor-objects "$OBJ" &&
+
+               # Do not die or crash when --ignore-missing is passed.
+               git -C repo rev-list --ignore-missing --objects \
+                       --exclude-promisor-objects "$OBJ" &&
+               git -C repo rev-list --ignore-missing --objects-edge-aggressive \
+                       --exclude-promisor-objects "$OBJ"
+       done
 '
 
 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '