list-objects.c: don't segfault for missing cmdline objects

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>

Matthew DeVore committed Dec 5, 2018 at 13:43 UTC 4cf67869b2ae3df7ab76b03c627f7b72d18d24ce
2 files changed +16 -2
revision.c
+2
@@ -1717,6 +1717,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
1717 if (!cant_be_filename)
1718 verify_non_filename(revs->prefix, arg);
1719 object = get_reference(revs, arg, &oid, flags ^ local_flags);
1720 + if (!object)
1721 + return revs->ignore_missing ? 0 : -1;
1722 add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags);
1723 add_pending_object_with_path(revs, object, arg, oc.mode, oc.path);
1724 free(oc.path);
t/t0410-partial-clone.sh
+14 -2
@@ -304,7 +304,7 @@ test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob
304 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
305 '
306
307 -test_expect_success 'rev-list accepts missing and promised objects on command line' '
307 +test_expect_success 'rev-list dies for missing objects on cmd line' '
308 rm -rf repo &&
309 test_create_repo repo &&
310 test_commit -C repo foo &&
@@ -321,7 +321,19 @@ test_expect_success 'rev-list accepts missing and promised objects on command li
321
322 git -C repo config core.repositoryformatversion 1 &&
323 git -C repo config extensions.partialclone "arbitrary string" &&
324 - git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" "$TREE" "$BLOB"
324 +
325 + for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
326 + test_must_fail git -C repo rev-list --objects \
327 + --exclude-promisor-objects "$OBJ" &&
328 + test_must_fail git -C repo rev-list --objects-edge-aggressive \
329 + --exclude-promisor-objects "$OBJ" &&
330 +
331 + # Do not die or crash when --ignore-missing is passed.
332 + git -C repo rev-list --ignore-missing --objects \
333 + --exclude-promisor-objects "$OBJ" &&
334 + git -C repo rev-list --ignore-missing --objects-edge-aggressive \
335 + --exclude-promisor-objects "$OBJ"
336 + done
337 '
338
339 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '