From 450870cba7a9bac94b5527021800bd8bf037c99c Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 24 Nov 2014 13:40:11 -0500 Subject: t1450: refactor ".", "..", and ".git" fsck tests We check that fsck notices and complains about confusing paths in trees. However, there are a few shortcomings: 1. We check only for these paths as file entries, not as intermediate paths (so ".git" and not ".git/foo"). 2. We check "." and ".." together, so it is possible that we notice only one and not the other. 3. We repeat a lot of boilerplate. Let's use some loops to be more thorough in our testing, and still end up with shorter code. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1450-fsck.sh | 57 +++++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 30 deletions(-) (limited to 't/t1450-fsck.sh') diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index d730734fde..4d8a4fe3c7 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -237,35 +237,32 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' ' ) ' -test_expect_success 'fsck notices "." and ".." in trees' ' - ( - git init dots && - cd dots && - blob=$(echo foo | git hash-object -w --stdin) && - tab=$(printf "\\t") && - git mktree <<-EOF && - 100644 blob $blob$tab. - 100644 blob $blob$tab.. - EOF - git fsck 2>out && - cat out && - grep "warning.*\\." out - ) -' - -test_expect_success 'fsck notices ".git" in trees' ' - ( - git init dotgit && - cd dotgit && - blob=$(echo foo | git hash-object -w --stdin) && - tab=$(printf "\\t") && - git mktree <<-EOF && - 100644 blob $blob$tab.git - EOF - git fsck 2>out && - cat out && - grep "warning.*\\.git" out - ) -' +while read name path; do + while read mode type; do + test_expect_success "fsck notices $path as $type" ' + ( + git init $name-$type && + cd $name-$type && + echo content >file && + git add file && + git commit -m base && + blob=$(git rev-parse :file) && + tree=$(git rev-parse HEAD^{tree}) && + value=$(eval "echo \$$type") && + printf "$mode $type %s\t%s" "$value" "$path" >bad && + git mktree out && + cat out && + grep "warning.*\\." out + )' + done <<-\EOF + 100644 blob + 040000 tree + EOF +done <<-\EOF +dot . +dotdot .. +dotgit .git +EOF test_done -- cgit v1.2.1 From 76e86fc6e3523d28e8db00e7b10c33c553d996b8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 24 Nov 2014 13:40:44 -0500 Subject: fsck: notice .git case-insensitively We complain about ".git" in a tree because it cannot be loaded into the index or checked out. Since we now also reject ".GIT" case-insensitively, fsck should notice the same, so that errors do not propagate. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1450-fsck.sh | 1 + 1 file changed, 1 insertion(+) (limited to 't/t1450-fsck.sh') diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 4d8a4fe3c7..0438712553 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -263,6 +263,7 @@ done <<-\EOF dot . dotdot .. dotgit .git +dotgit-case .GIT EOF test_done -- cgit v1.2.1 From a18fcc9ff22b714e7df30c400c05542f52830eb0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 15 Dec 2014 18:21:57 -0500 Subject: 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 Signed-off-by: Junio C Hamano --- t/t1450-fsck.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 't/t1450-fsck.sh') diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 0438712553..8158b98e6f 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -237,9 +237,10 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' ' ) ' -while read name path; do +while read name path pretty; do while read mode type; do - test_expect_success "fsck notices $path as $type" ' + : ${pretty:=$path} + test_expect_success "fsck notices $pretty as $type" ' ( git init $name-$type && cd $name-$type && @@ -259,11 +260,12 @@ while read name path; do 100644 blob 040000 tree EOF -done <<-\EOF +done <<-EOF dot . dotdot .. dotgit .git dotgit-case .GIT +dotgit-unicode .gI${u200c}T .gI{u200c}T EOF test_done -- cgit v1.2.1 From d08c13b947335cc48ecc1a8453d97b7147c2d6d6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 10 Dec 2014 22:28:27 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- t/t1450-fsck.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 't/t1450-fsck.sh') diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 8158b98e6f..6edd99a81e 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -251,10 +251,10 @@ while read name path pretty; do tree=$(git rev-parse HEAD^{tree}) && value=$(eval "echo \$$type") && printf "$mode $type %s\t%s" "$value" "$path" >bad && - git mktree out && cat out && - grep "warning.*\\." out + grep "warning.*tree $bad_tree" out )' done <<-\EOF 100644 blob @@ -266,6 +266,11 @@ dotdot .. dotgit .git dotgit-case .GIT dotgit-unicode .gI${u200c}T .gI{u200c}T +dotgit-case2 .Git +git-tilde1 git~1 +dotgitdot .git. +dot-backslash-case .\\\\.GIT\\\\foobar +dotgit-case-backslash .git\\\\foobar EOF test_done -- cgit v1.2.1