Skip to content

Commit a18fcc9

Browse files
peffgitster
authored andcommitted
fsck: complain about HFS+ ".git" aliases in trees
Now that the index can block pathnames that case-fold to ".git" on HFS+, it would be helpful for fsck to notice such problematic paths. This lets servers which use receive.fsckObjects block them before the damage spreads. Note that the fsck check is always on, even for systems without core.protectHFS set. This is technically more restrictive than we need to be, as a set of users on ext4 could happily use these odd filenames without caring about HFS+. However, on balance, it's helpful for all servers to block these (because the paths can be used for mischief, and servers which bother to fsck would want to stop the spread whether they are on HFS+ themselves or not), and hardly anybody will be affected (because the blocked names are variants of .git with invisible Unicode code-points mixed in, meaning mischief is almost certainly what the tree author had in mind). Ideally these would be controlled by a separate "fsck.protectHFS" flag. However, it would be much nicer to be able to enable/disable _any_ fsck flag individually, and any scheme we choose should match such a system. Given the likelihood of anybody using such a path in practice, it is not unreasonable to wait until such a system materializes. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a42643a commit a18fcc9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

fsck.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "commit.h"
77
#include "tag.h"
88
#include "fsck.h"
9+
#include "utf8.h"
910

1011
static int fsck_walk_tree(struct tree *tree, fsck_walk_func walk, void *data)
1112
{
@@ -175,7 +176,7 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
175176
has_dot = 1;
176177
if (!strcmp(name, ".."))
177178
has_dotdot = 1;
178-
if (!strcasecmp(name, ".git"))
179+
if (!strcasecmp(name, ".git") || is_hfs_dotgit(name))
179180
has_dotgit = 1;
180181
has_zero_pad |= *(char *)desc.buffer == '0';
181182
update_tree_entry(&desc);

t/t1450-fsck.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,10 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' '
237237
)
238238
'
239239

240-
while read name path; do
240+
while read name path pretty; do
241241
while read mode type; do
242-
test_expect_success "fsck notices $path as $type" '
242+
: ${pretty:=$path}
243+
test_expect_success "fsck notices $pretty as $type" '
243244
(
244245
git init $name-$type &&
245246
cd $name-$type &&
@@ -259,11 +260,12 @@ while read name path; do
259260
100644 blob
260261
040000 tree
261262
EOF
262-
done <<-\EOF
263+
done <<-EOF
263264
dot .
264265
dotdot ..
265266
dotgit .git
266267
dotgit-case .GIT
268+
dotgit-unicode .gI${u200c}T .gI{u200c}T
267269
EOF
268270

269271
test_done

0 commit comments

Comments
 (0)