From 431acd2de89ad5ec0a3e6ae6141e699c4a824ae1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 11 Jun 2018 04:35:40 -0400 Subject: [PATCH 1/2] t7415: don't bother creating commit for symlink test Early versions of the fsck .gitmodules detection code actually required a tree to be at the root of a commit for it to be checked for .gitmodules. What we ended up with in 159e7b080b (fsck: detect gitmodules files, 2018-05-02), though, finds a .gitmodules file in _any_ tree (see that commit for more discussion). As a result, there's no need to create a commit in our tests. Let's drop it in the name of simplicity. And since that was the only thing referencing $tree, we can pull our tree creation out of a command substitution. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t7415-submodule-names.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/t/t7415-submodule-names.sh b/t/t7415-submodule-names.sh index a770d92a55..541bd81684 100755 --- a/t/t7415-submodule-names.sh +++ b/t/t7415-submodule-names.sh @@ -135,13 +135,10 @@ test_expect_success 'fsck detects symlinked .gitmodules file' ' tricky="[foo]bar=true" && content=$(git hash-object -w ../.gitmodules) && target=$(printf "$tricky" | git hash-object -w --stdin) && - tree=$( - { - printf "100644 blob $content\t$tricky\n" && - printf "120000 blob $target\t.gitmodules\n" - } | git mktree - ) && - commit=$(git commit-tree $tree) && + { + printf "100644 blob $content\t$tricky\n" && + printf "120000 blob $target\t.gitmodules\n" + } | git mktree && # Check not only that we fail, but that it is due to the # symlink detector; this grep string comes from the config From 47cc91310a81ca606e6bebcccf168bc1cb297d8e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 11 Jun 2018 04:35:45 -0400 Subject: [PATCH 2/2] fsck: avoid looking at NULL blob->object Commit 159e7b080b (fsck: detect gitmodules files, 2018-05-02) taught fsck to look at the content of .gitmodules files. If the object turns out not to be a blob at all, we just complain and punt on checking the content. And since this was such an obvious and trivial code path, I didn't even bother to add a test. Except it _does_ do one non-trivial thing, which is call the report() function, which wants us to pass a pointer to a "struct object". Which we don't have (we have only a "struct object_id"). So we erroneously pass a NULL object to report(), which gets dereferenced and causes a segfault. It seems like we could refactor report() to just take the object_id itself. But we pass the object pointer along to a callback function, and indeed this ends up in builtin/fsck.c's objreport() which does want to look at other parts of the object (like the type). So instead, let's just use lookup_unknown_object() to get the real "struct object", and pass that. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 3 ++- t/t7415-submodule-names.sh | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/fsck.c b/fsck.c index 9339f31513..35af51553d 100644 --- a/fsck.c +++ b/fsck.c @@ -1032,7 +1032,8 @@ int fsck_finish(struct fsck_options *options) blob = lookup_blob(oid); if (!blob) { - ret |= report(options, &blob->object, + struct object *obj = lookup_unknown_object(oid->hash); + ret |= report(options, obj, FSCK_MSG_GITMODULES_BLOB, "non-blob found at .gitmodules"); continue; diff --git a/t/t7415-submodule-names.sh b/t/t7415-submodule-names.sh index 541bd81684..3c0f1a102a 100755 --- a/t/t7415-submodule-names.sh +++ b/t/t7415-submodule-names.sh @@ -148,4 +148,22 @@ test_expect_success 'fsck detects symlinked .gitmodules file' ' ) ' +test_expect_success 'fsck detects non-blob .gitmodules' ' + git init non-blob && + ( + cd non-blob && + + # As above, make the funny tree directly to avoid index + # restrictions. + mkdir subdir && + cp ../.gitmodules subdir/file && + git add subdir/file && + git commit -m ok && + git ls-tree HEAD | sed s/subdir/.gitmodules/ | git mktree && + + test_must_fail git fsck 2>output && + grep gitmodulesBlob output + ) +' + test_done