Skip to content

Commit bccc37f

Browse files
me-andgitster
authored andcommitted
cygwin: disallow backslashes in file names
The backslash character is not a valid part of a file name on Windows. If, in Windows, Git attempts to write a file that has a backslash character in the filename, it will be incorrectly interpreted as a directory separator. This caused CVE-2019-1354 in MinGW, as this behaviour can be manipulated to cause the checkout to write to files it ought not write to, such as adding code to the .git/hooks directory. This was fixed by e1d911d (mingw: disallow backslash characters in tree objects' file names, 2019-09-12). However, the vulnerability also exists in Cygwin: while Cygwin mostly provides a POSIX-like path system, it will still interpret a backslash as a directory separator. To avoid this vulnerability, CVE-2021-29468, extend the previous fix to also apply to Cygwin. Similarly, extend the test case added by the previous version of the commit. The test suite doesn't have an easy way to say "run this test if in MinGW or Cygwin", so add a new test prerequisite that covers both. As well as checking behaviour in the presence of paths containing backslashes, the existing test also checks behaviour in the presence of paths that differ only by the presence of a trailing ".". MinGW follows normal Windows application behaviour and treats them as the same path, but Cygwin more closely emulates *nix systems (at the expense of compatibility with native Windows applications) and will create and distinguish between such paths. Gate the relevant bit of that test accordingly. Reported-by: RyotaK <security@ryotak.me> Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Adam Dinwoodie <adam@dinwoodie.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 48bf2fa commit bccc37f

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

read-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ int verify_path(const char *path, unsigned mode)
985985
}
986986
}
987987
if (protect_ntfs) {
988-
#ifdef GIT_WINDOWS_NATIVE
988+
#if defined GIT_WINDOWS_NATIVE || defined __CYGWIN__
989989
if (c == '\\')
990990
return 0;
991991
#endif

t/t7415-submodule-names.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ test_expect_success 'fsck detects corrupt .gitmodules' '
191191
)
192192
'
193193

194-
test_expect_success MINGW 'prevent git~1 squatting on Windows' '
194+
test_expect_success WINDOWS 'prevent git~1 squatting on Windows' '
195195
git init squatting &&
196196
(
197197
cd squatting &&
@@ -219,10 +219,13 @@ test_expect_success MINGW 'prevent git~1 squatting on Windows' '
219219
test_tick &&
220220
git -c core.protectNTFS=false commit -m "module"
221221
) &&
222-
test_must_fail git -c core.protectNTFS=false \
223-
clone --recurse-submodules squatting squatting-clone 2>err &&
224-
test_i18ngrep -e "directory not empty" -e "not an empty directory" err &&
225-
! grep gitdir squatting-clone/d/a/git~2
222+
if test_have_prereq MINGW
223+
then
224+
test_must_fail git -c core.protectNTFS=false \
225+
clone --recurse-submodules squatting squatting-clone 2>err &&
226+
test_i18ngrep -e "directory not empty" -e "not an empty directory" err &&
227+
! grep gitdir squatting-clone/d/a/git~2
228+
fi
226229
'
227230

228231
test_expect_success 'git dirs of sibling submodules must not be nested' '

t/test-lib.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ case $uname_s in
14571457
test_set_prereq NATIVE_CRLF
14581458
test_set_prereq SED_STRIPS_CR
14591459
test_set_prereq GREP_STRIPS_CR
1460+
test_set_prereq WINDOWS
14601461
GIT_TEST_CMP=mingw_test_cmp
14611462
;;
14621463
*CYGWIN*)
@@ -1465,6 +1466,7 @@ case $uname_s in
14651466
test_set_prereq CYGWIN
14661467
test_set_prereq SED_STRIPS_CR
14671468
test_set_prereq GREP_STRIPS_CR
1469+
test_set_prereq WINDOWS
14681470
;;
14691471
*)
14701472
test_set_prereq POSIXPERM

0 commit comments

Comments
 (0)