git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fsck: avoid looking at NULL blob->object
@ 2018-06-09  8:32 Jeff King
  2018-06-09  8:38 ` Eric Sunshine
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Jeff King @ 2018-06-09  8:32 UTC (permalink / raw)
  To: git

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 passed the NULL object, which
ends up segfaulting.

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 <peff@peff.net>
---
The problem is in v2.17.1, and of course the v2.18 release candidates.

 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 bcae2c30e6..48e7e36869 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1036,7 +1036,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 a770d92a55..63c767bf99 100755
--- a/t/t7415-submodule-names.sh
+++ b/t/t7415-submodule-names.sh
@@ -151,4 +151,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 directly to avoid index restrictions.
+		mkdir subdir &&
+		cp ../.gitmodules subdir/file &&
+		git add subdir/file &&
+		git commit -m ok &&
+		tree=$(git ls-tree HEAD | sed s/subdir/.gitmodules/ | git mktree) &&
+		commit=$(git commit-tree $tree) &&
+
+		test_must_fail git fsck 2>output &&
+		grep gitmodulesBlob output
+	)
+'
+
 test_done
-- 
2.18.0.rc1.446.g4486251e51

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-06-12  9:51 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-09  8:32 [PATCH] fsck: avoid looking at NULL blob->object Jeff King
2018-06-09  8:38 ` Eric Sunshine
2018-06-09  9:19   ` Jeff King
2018-06-09  8:45 ` Duy Nguyen
2018-06-09  9:20   ` Jeff King
2018-06-09  8:50 ` Martin Ågren
2018-06-09  9:21   ` Jeff King
2018-06-09 13:44     ` Martin Ågren
2018-06-12  9:51       ` Jeff King
2018-06-09  9:30 ` [PATCH v2 0/2] .gitmodules fsck cleanups Jeff King
2018-06-09  9:31   ` [PATCH v2 1/2] t7415: don't bother creating commit for symlink test Jeff King
2018-06-09  9:46     ` SZEDER Gábor
2018-06-11  8:35       ` [PATCH v3 0/2] .gitmodules fsck cleanups Jeff King
2018-06-11  8:35         ` [PATCH v3 1/2] t7415: don't bother creating commit for symlink test Jeff King
2018-06-11  8:35         ` [PATCH v3 2/2] fsck: avoid looking at NULL blob->object Jeff King
2018-06-09  9:31   ` [PATCH v2 " Jeff King
2018-06-09  9:50     ` SZEDER Gábor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).