Skip to content

Commit d08c13b

Browse files
dschogitster
authored andcommitted
fsck: complain about NTFS ".git" aliases in trees
Now that the index can block pathnames that can be mistaken to mean ".git" on NTFS and FAT32, 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.protectNTFS 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 NTFS. 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 NTFS themselves or not), and hardly anybody will be affected (because the blocked names are variants of .git or git~1, meaning mischief is almost certainly what the tree author had in mind). Ideally these would be controlled by a separate "fsck.protectNTFS" 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: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b4c6ef commit d08c13b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

fsck.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
176176
has_dot = 1;
177177
if (!strcmp(name, ".."))
178178
has_dotdot = 1;
179-
if (!strcasecmp(name, ".git") || is_hfs_dotgit(name))
179+
if (!strcasecmp(name, ".git") || is_hfs_dotgit(name) ||
180+
is_ntfs_dotgit(name))
180181
has_dotgit = 1;
181182
has_zero_pad |= *(char *)desc.buffer == '0';
182183
update_tree_entry(&desc);

t/t1450-fsck.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ while read name path pretty; do
251251
tree=$(git rev-parse HEAD^{tree}) &&
252252
value=$(eval "echo \$$type") &&
253253
printf "$mode $type %s\t%s" "$value" "$path" >bad &&
254-
git mktree <bad &&
254+
bad_tree=$(git mktree <bad) &&
255255
git fsck 2>out &&
256256
cat out &&
257-
grep "warning.*\\." out
257+
grep "warning.*tree $bad_tree" out
258258
)'
259259
done <<-\EOF
260260
100644 blob
@@ -266,6 +266,11 @@ dotdot ..
266266
dotgit .git
267267
dotgit-case .GIT
268268
dotgit-unicode .gI${u200c}T .gI{u200c}T
269+
dotgit-case2 .Git
270+
git-tilde1 git~1
271+
dotgitdot .git.
272+
dot-backslash-case .\\\\.GIT\\\\foobar
273+
dotgit-case-backslash .git\\\\foobar
269274
EOF
270275

271276
test_done

0 commit comments

Comments
 (0)