Skip to content

Commit 0786882

Browse files
j6tgitster
authored andcommitted
t1301-shared-repo: fix forced modes test
This test was added recently (5a688fe, "core.sharedrepository = 0mode" should set, not loosen; 2009-03-28). It checked the result of a sed invocation for emptyness, but in some cases it forgot to print anything at all, so that those checks would never be false. Due to this mistake, it went unnoticed that the files in objects/info are not necessarily 0440, but can also be 0660. Because the 0mode setting tries to guarantee that the files are accessible only to the people they are meant to be used by, we should only make sure that they are readable by the user and the group when the configuration is set to 0660. It is a separate matter from the core.shredrepository settings that w-bit from immutable object files under objects/[0-9a-f][0-9a-f] directories should be dropped. COMMIT_EDITMSG is still world-readable, but it (and any transient files that are meant for repositories with a work tree) does not matter. If you are working on a shared machine and on a sekrit stuff, the root of the work tree would be with mode 0700 (or 0750 to allow peeking by other people in the group), and that would mean that .git/COMMIT_EDITMSG in such a repository would not be readable by the strangers anyway. Also, in the real-world use case, .git/COMMIT_EDITMSG will be given to an arbitrary editor the user happens to use, and we have no guarantee what it does (e.g. it may create a new file with umask and replace, it may rewrite in place, it may leave an editor backup file but use umask to create it, etc.), and the protection of the file lies majorly on the protection of the root of the work tree. This test cannot be run on Windows; it requires POSIXPERM when merged to 'master'. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b89eaa commit 0786882

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

t/t1301-shared-repo.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ test_expect_success 'forced modes' '
141141
git commit -a -m initial &&
142142
git repack
143143
) &&
144-
find new/.git -print |
144+
# List repository files meant to be protected; note that
145+
# COMMIT_EDITMSG does not matter---0mode is not about a
146+
# repository with a work tree.
147+
find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
145148
xargs ls -ld >actual &&
146149
147150
# Everything must be unaccessible to others
148-
test -z "$(sed -n -e "/^.......---/d" actual)" &&
151+
test -z "$(sed -e "/^.......---/d" actual)" &&
149152
150153
# All directories must have either 2770 or 770
151154
test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
@@ -156,10 +159,11 @@ test_expect_success 'forced modes' '
156159
p
157160
}" actual)" &&
158161
159-
# All files inside objects must be 0440
162+
# All files inside objects must be accessible by us
160163
test -z "$(sed -n -e "/objects\//{
161164
/^d/d
162-
/^-r--r-----/d
165+
/^-r.-r.----/d
166+
p
163167
}" actual)"
164168
'
165169

0 commit comments

Comments
 (0)