]> git.ipfire.org Git - thirdparty/git.git/commit
fsck: actually detect bad file modes in trees
authorJeff King <peff@peff.net>
Wed, 10 Aug 2022 21:02:45 +0000 (17:02 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Aug 2022 21:26:27 +0000 (14:26 -0700)
commit53602a937dc9eacd67b6afcd781f7b15bb02682f
treed208630a2d37d45d89f4642beba378d6f1d10aaa
parentec18b10bf20574fc6d60c966412a11c81f9c17e0
fsck: actually detect bad file modes in trees

We use the normal tree_desc code to iterate over trees in fsck, meaning
we only see the canonicalized modes it returns. And hence we'd never see
anything unexpected, since it will coerce literally any garbage into one
of our normal and accepted modes.

We can use the new RAW_MODES flag to see the real modes, and then use
the existing code to actually analyze them. The existing code is written
as allow-known-good, so there's not much point in testing a variety of
breakages. The one tested here should be S_IFREG but with nonsense
permissions.

Do note that the error-reporting here isn't great. We don't mention the
specific bad mode, but just that the tree has one or more broken modes.
But when you go to look at it with "git ls-tree", we'll report the
canonicalized mode! This isn't ideal, but given that this should come up
rarely, and that any number of other tree corruptions might force you
into looking at the binary bytes via "cat-file", it's not the end of the
world. And it's something we can improve on top later if we choose.

Reported-by: Xavier Morel <xavier.morel@masklinn.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsck.c
t/t1450-fsck.sh