unpack-objects: call fsck_finish() after fscking objects

As with the previous commit, we must call fsck's "finish" function in order to catch any queued objects for .gitmodules checks. This second pass will be able to access any incoming objects, because we will have exploded them to loose objects by now. This isn't quite ideal, because it means that bad objects may have been written to the object database (and a subsequent operation could then reference them, even if the other side doesn't send the objects again). However, this is sufficient when used with receive.fsckObjects, since those loose objects will all be placed in a temporary quarantine area that will get wiped if we find any problems. Signed-off-by: Jeff King <peff@peff.net>

Jeff King committed May 4, 2018 at 19:40 UTC 6e328d6caef218db320978e3e251009135d87d0e
2 files changed +11 -1
builtin/unpack-objects.c
+4 -1
@@ -572,8 +572,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
572 unpack_all();
573 the_hash_algo->update_fn(&ctx, buffer, offset);
574 the_hash_algo->final_fn(oid.hash, &ctx);
575 - if (strict)
575 + if (strict) {
576 write_rest();
577 + if (fsck_finish(&fsck_options))
578 + die(_("fsck error in pack objects"));
579 + }
580 if (hashcmp(fill(the_hash_algo->rawsz), oid.hash))
581 die("final sha1 did not match");
582 use(the_hash_algo->rawsz);
t/t7415-submodule-names.sh
+7
@@ -77,4 +77,11 @@ test_expect_success 'fsck detects evil superproject' '
77 test_must_fail git fsck
78 '
79
80 +test_expect_success 'transfer.fsckObjects detects evil superproject (unpack)' '
81 + rm -rf dst.git &&
82 + git init --bare dst.git &&
83 + git -C dst.git config transfer.fsckObjects true &&
84 + test_must_fail git push dst.git HEAD
85 +'
86 +
87 test_done