Skip to content

Commit e1d911d

Browse files
committed
mingw: disallow backslash characters in tree objects' file names
The backslash character is not a valid part of a file name on Windows. Hence it is dangerous to allow writing files that were unpacked from tree objects, when the stored file name contains a backslash character: it will be misinterpreted as directory separator. This not only causes ambiguity when a tree contains a blob `a\b` and a tree `a` that contains a blob `b`, but it also can be used as part of an attack vector to side-step the careful protections against writing into the `.git/` directory during a clone of a maliciously-crafted repository. Let's prevent that, addressing CVE-2019-1354. Note: we guard against backslash characters in tree objects' file names _only_ on Windows (because on other platforms, even on those where NTFS volumes can be mounted, the backslash character is _not_ a directory separator), and _only_ when `core.protectNTFS = true` (because users might need to generate tree objects for other platforms, of course without touching the worktree, e.g. using `git update-index --cacheinfo`). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0060fd1 commit e1d911d

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

t/t1450-fsck.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ while read name path pretty; do
419419
(
420420
git init $name-$type &&
421421
cd $name-$type &&
422+
git config core.protectNTFS false &&
422423
echo content >file &&
423424
git add file &&
424425
git commit -m base &&

t/t7415-submodule-names.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,18 @@ test_expect_success MINGW 'prevent git~1 squatting on Windows' '
8989
git hash-object -w --stdin)" &&
9090
rev="$(git rev-parse --verify HEAD)" &&
9191
hash="$(echo x | git hash-object -w --stdin)" &&
92-
git update-index --add \
92+
git -c core.protectNTFS=false update-index --add \
9393
--cacheinfo 100644,$modules,.gitmodules \
9494
--cacheinfo 160000,$rev,c \
9595
--cacheinfo 160000,$rev,d\\a \
9696
--cacheinfo 100644,$hash,d./a/x \
9797
--cacheinfo 100644,$hash,d./a/..git &&
9898
test_tick &&
99-
git commit -m "module"
99+
git -c core.protectNTFS=false commit -m "module" &&
100+
test_must_fail git show HEAD: 2>err &&
101+
test_i18ngrep backslash err
100102
) &&
101-
test_must_fail git \
103+
test_must_fail git -c core.protectNTFS=false \
102104
clone --recurse-submodules squatting squatting-clone 2>err &&
103105
test_i18ngrep "directory not empty" err &&
104106
! grep gitdir squatting-clone/d/a/git~2

t/t9350-fast-export.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ test_expect_success 'directory becomes symlink' '
421421

422422
test_expect_success 'fast-export quotes pathnames' '
423423
git init crazy-paths &&
424+
test_config -C crazy-paths core.protectNTFS false &&
424425
(cd crazy-paths &&
425426
blob=$(echo foo | git hash-object -w --stdin) &&
426427
git update-index --add \

tree-walk.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
4141
strbuf_addstr(err, _("empty filename in tree entry"));
4242
return -1;
4343
}
44+
#ifdef GIT_WINDOWS_NATIVE
45+
if (protect_ntfs && strchr(path, '\\')) {
46+
strbuf_addf(err, _("filename in tree entry contains backslash: '%s'"), path);
47+
return -1;
48+
}
49+
#endif
4450
len = strlen(path) + 1;
4551

4652
/* Initialize the descriptor entry */

0 commit comments

Comments
 (0)