Skip to content

Commit 47cc913

Browse files
peffgitster
authored andcommitted
fsck: avoid looking at NULL blob->object
Commit 159e7b0 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 431acd2 commit 47cc913

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

fsck.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ int fsck_finish(struct fsck_options *options)
10321032

10331033
blob = lookup_blob(oid);
10341034
if (!blob) {
1035-
ret |= report(options, &blob->object,
1035+
struct object *obj = lookup_unknown_object(oid->hash);
1036+
ret |= report(options, obj,
10361037
FSCK_MSG_GITMODULES_BLOB,
10371038
"non-blob found at .gitmodules");
10381039
continue;

t/t7415-submodule-names.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,22 @@ test_expect_success 'fsck detects symlinked .gitmodules file' '
148148
)
149149
'
150150

151+
test_expect_success 'fsck detects non-blob .gitmodules' '
152+
git init non-blob &&
153+
(
154+
cd non-blob &&
155+
156+
# As above, make the funny tree directly to avoid index
157+
# restrictions.
158+
mkdir subdir &&
159+
cp ../.gitmodules subdir/file &&
160+
git add subdir/file &&
161+
git commit -m ok &&
162+
git ls-tree HEAD | sed s/subdir/.gitmodules/ | git mktree &&
163+
164+
test_must_fail git fsck 2>output &&
165+
grep gitmodulesBlob output
166+
)
167+
'
168+
151169
test_done

0 commit comments

Comments
 (0)