Skip to content

Commit 6898b79

Browse files
committed
Sync with v1.8.5.6
* maint-1.8.5: Git 1.8.5.6 fsck: complain about NTFS ".git" aliases in trees read-cache: optionally disallow NTFS .git variants path: add is_ntfs_dotgit() helper fsck: complain about HFS+ ".git" aliases in trees read-cache: optionally disallow HFS+ .git variants utf8: add is_hfs_dotgit() helper fsck: notice .git case-insensitively t1450: refactor ".", "..", and ".git" fsck tests verify_dotfile(): reject .git case-insensitively read-tree: add tests for confusing paths like ".." and ".git" unpack-trees: propagate errors adding entries to the index
2 parents 9181365 + 5c8213a commit 6898b79

16 files changed

+297
-39
lines changed

Documentation/RelNotes/1.8.5.6.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Git v1.8.5.6 Release Notes
2+
==========================
3+
4+
Fixes since v1.8.5.5
5+
--------------------
6+
7+
* We used to allow committing a path ".Git/config" with Git that is
8+
running on a case sensitive filesystem, but an attempt to check out
9+
such a path with Git that runs on a case insensitive filesystem
10+
would have clobbered ".git/config", which is definitely not what
11+
the user would have expected. Git now prevents you from tracking
12+
a path with ".Git" (in any case combination) as a path component.
13+
14+
* On Windows, certain path components that are different from ".git"
15+
are mapped to ".git", e.g. "git~1/config" is treated as if it were
16+
".git/config". HFS+ has a similar issue, where certain unicode
17+
codepoints are ignored, e.g. ".g\u200cit/config" is treated as if
18+
it were ".git/config". Pathnames with these potential issues are
19+
rejected on the affected systems. Git on systems that are not
20+
affected by this issue (e.g. Linux) can also be configured to
21+
reject them to ensure cross platform interoperability of the hosted
22+
projects.
23+
24+
* "git fsck" notices a tree object that records such a path that can
25+
be confused with ".git", and with receive.fsckObjects configuration
26+
set to true, an attempt to "git push" such a tree object will be
27+
rejected. Such a path may not be a problem on a well behaving
28+
filesystem but in order to protect those on HFS+ and on case
29+
insensitive filesystems, this check is enabled on all platforms.
30+
31+
A big "thanks!" for bringing this issue to us goes to our friends in
32+
the Mercurial land, namely, Matt Mackall and Augie Fackler.
33+
34+
Also contains typofixes, documentation updates and trivial code clean-ups.

Documentation/config.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ core.precomposeunicode::
234234
When false, file names are handled fully transparent by Git,
235235
which is backward compatible with older versions of Git.
236236

237+
core.protectHFS::
238+
If set to true, do not allow checkout of paths that would
239+
be considered equivalent to `.git` on an HFS+ filesystem.
240+
Defaults to `true` on Mac OS, and `false` elsewhere.
241+
242+
core.protectNTFS::
243+
If set to true, do not allow checkout of paths that would
244+
cause problems with the NTFS filesystem, e.g. conflict with
245+
8.3 "short" names.
246+
Defaults to `true` on Windows, and `false` elsewhere.
247+
237248
core.trustctime::
238249
If false, the ctime differences between the index and the
239250
working tree are ignored; useful when the inode change time

Documentation/git.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ Documentation for older releases are available here:
5252
link:RelNotes/1.9.1.txt[1.9.1],
5353
link:RelNotes/1.9.0.txt[1.9.0].
5454

55-
* link:v1.8.5.5/git.html[documentation for release 1.8.5.5]
55+
* link:v1.8.5.6/git.html[documentation for release 1.8.5.6]
5656

5757
* release notes for
58+
link:RelNotes/1.8.5.6.txt[1.8.5.6],
5859
link:RelNotes/1.8.5.5.txt[1.8.5.5],
5960
link:RelNotes/1.8.5.4.txt[1.8.5.4],
6061
link:RelNotes/1.8.5.3.txt[1.8.5.3],

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ extern int fsync_object_files;
587587
extern int core_preload_index;
588588
extern int core_apply_sparse_checkout;
589589
extern int precomposed_unicode;
590+
extern int protect_hfs;
591+
extern int protect_ntfs;
590592

591593
/*
592594
* The character that begins a commented line in user-editable file
@@ -782,6 +784,7 @@ int longest_ancestor_length(const char *path, struct string_list *prefixes);
782784
char *strip_path_suffix(const char *path, const char *suffix);
783785
int daemon_avoid_alias(const char *path);
784786
int offset_1st_component(const char *path);
787+
extern int is_ntfs_dotgit(const char *name);
785788

786789
/* object replacement */
787790
#define LOOKUP_REPLACE_OBJECT 1

config.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,16 @@ static int git_default_core_config(const char *var, const char *value)
885885
return 0;
886886
}
887887

888+
if (!strcmp(var, "core.protecthfs")) {
889+
protect_hfs = git_config_bool(var, value);
890+
return 0;
891+
}
892+
893+
if (!strcmp(var, "core.protectntfs")) {
894+
protect_ntfs = git_config_bool(var, value);
895+
return 0;
896+
}
897+
888898
/* Add other config variables here and to Documentation/config.txt. */
889899
return 0;
890900
}

config.mak.uname

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ ifeq ($(uname_S),Darwin)
9797
HAVE_DEV_TTY = YesPlease
9898
COMPAT_OBJS += compat/precompose_utf8.o
9999
BASIC_CFLAGS += -DPRECOMPOSE_UNICODE
100+
BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1
100101
endif
101102
ifeq ($(uname_S),SunOS)
102103
NEEDS_SOCKET = YesPlease
@@ -369,6 +370,7 @@ ifeq ($(uname_S),Windows)
369370
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib
370371
PTHREAD_LIBS =
371372
lib =
373+
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
372374
ifndef DEBUG
373375
BASIC_CFLAGS += -GL -Os -MT
374376
BASIC_LDFLAGS += -LTCG
@@ -513,6 +515,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
513515
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
514516
compat/win32/pthread.o compat/win32/syslog.o \
515517
compat/win32/dirent.o
518+
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
516519
BASIC_LDFLAGS += -Wl,--large-address-aware
517520
EXTLIBS += -lws2_32
518521
GITLIBS += git.res

environment.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
6464
struct startup_info *startup_info;
6565
unsigned long pack_size_limit_cfg;
6666

67+
#ifndef PROTECT_HFS_DEFAULT
68+
#define PROTECT_HFS_DEFAULT 0
69+
#endif
70+
int protect_hfs = PROTECT_HFS_DEFAULT;
71+
72+
#ifndef PROTECT_NTFS_DEFAULT
73+
#define PROTECT_NTFS_DEFAULT 0
74+
#endif
75+
int protect_ntfs = PROTECT_NTFS_DEFAULT;
76+
6777
/*
6878
* The character that begins a commented line in user-editable file
6979
* that is subject to stripspace.

fsck.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "commit.h"
77
#include "tag.h"
88
#include "fsck.h"
9+
#include "utf8.h"
910

1011
static int fsck_walk_tree(struct tree *tree, fsck_walk_func walk, void *data)
1112
{
@@ -175,7 +176,8 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
175176
has_dot = 1;
176177
if (!strcmp(name, ".."))
177178
has_dotdot = 1;
178-
if (!strcmp(name, ".git"))
179+
if (!strcasecmp(name, ".git") || is_hfs_dotgit(name) ||
180+
is_ntfs_dotgit(name))
179181
has_dotgit = 1;
180182
has_zero_pad |= *(char *)desc.buffer == '0';
181183
update_tree_entry(&desc);

path.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,36 @@ int offset_1st_component(const char *path)
830830
return 2 + is_dir_sep(path[2]);
831831
return is_dir_sep(path[0]);
832832
}
833+
834+
static int only_spaces_and_periods(const char *path, size_t len, size_t skip)
835+
{
836+
if (len < skip)
837+
return 0;
838+
len -= skip;
839+
path += skip;
840+
while (len-- > 0) {
841+
char c = *(path++);
842+
if (c != ' ' && c != '.')
843+
return 0;
844+
}
845+
return 1;
846+
}
847+
848+
int is_ntfs_dotgit(const char *name)
849+
{
850+
int len;
851+
852+
for (len = 0; ; len++)
853+
if (!name[len] || name[len] == '\\' || is_dir_sep(name[len])) {
854+
if (only_spaces_and_periods(name, len, 4) &&
855+
!strncasecmp(name, ".git", 4))
856+
return 1;
857+
if (only_spaces_and_periods(name, len, 5) &&
858+
!strncasecmp(name, "git~1", 5))
859+
return 1;
860+
if (name[len] != '\\')
861+
return 0;
862+
name += len + 1;
863+
len = -1;
864+
}
865+
}

read-cache.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "resolve-undo.h"
1515
#include "strbuf.h"
1616
#include "varint.h"
17+
#include "utf8.h"
1718

1819
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
1920
unsigned int options);
@@ -752,9 +753,10 @@ static int verify_dotfile(const char *rest)
752753
* shares the path end test with the ".." case.
753754
*/
754755
case 'g':
755-
if (rest[1] != 'i')
756+
case 'G':
757+
if (rest[1] != 'i' && rest[1] != 'I')
756758
break;
757-
if (rest[2] != 't')
759+
if (rest[2] != 't' && rest[2] != 'T')
758760
break;
759761
rest += 2;
760762
/* fallthrough */
@@ -778,6 +780,10 @@ int verify_path(const char *path)
778780
return 1;
779781
if (is_dir_sep(c)) {
780782
inside:
783+
if (protect_hfs && is_hfs_dotgit(path))
784+
return 0;
785+
if (protect_ntfs && is_ntfs_dotgit(path))
786+
return 0;
781787
c = *path++;
782788
if ((c == '.' && !verify_dotfile(path)) ||
783789
is_dir_sep(c) || c == '\0')

t/t1014-read-tree-confusing.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/sh
2+
3+
test_description='check that read-tree rejects confusing paths'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'create base tree' '
7+
echo content >file &&
8+
git add file &&
9+
git commit -m base &&
10+
blob=$(git rev-parse HEAD:file) &&
11+
tree=$(git rev-parse HEAD^{tree})
12+
'
13+
14+
test_expect_success 'enable core.protectHFS for rejection tests' '
15+
git config core.protectHFS true
16+
'
17+
18+
test_expect_success 'enable core.protectNTFS for rejection tests' '
19+
git config core.protectNTFS true
20+
'
21+
22+
while read path pretty; do
23+
: ${pretty:=$path}
24+
case "$path" in
25+
*SPACE)
26+
path="${path%SPACE} "
27+
;;
28+
esac
29+
test_expect_success "reject $pretty at end of path" '
30+
printf "100644 blob %s\t%s" "$blob" "$path" >tree &&
31+
bogus=$(git mktree <tree) &&
32+
test_must_fail git read-tree $bogus
33+
'
34+
35+
test_expect_success "reject $pretty as subtree" '
36+
printf "040000 tree %s\t%s" "$tree" "$path" >tree &&
37+
bogus=$(git mktree <tree) &&
38+
test_must_fail git read-tree $bogus
39+
'
40+
done <<-EOF
41+
.
42+
..
43+
.git
44+
.GIT
45+
${u200c}.Git {u200c}.Git
46+
.gI${u200c}T .gI{u200c}T
47+
.GiT${u200c} .GiT{u200c}
48+
git~1
49+
.git.SPACE .git.{space}
50+
.\\\\.GIT\\\\foobar backslashes
51+
.git\\\\foobar backslashes2
52+
EOF
53+
54+
test_expect_success 'utf-8 paths allowed with core.protectHFS off' '
55+
test_when_finished "git read-tree HEAD" &&
56+
test_config core.protectHFS false &&
57+
printf "100644 blob %s\t%s" "$blob" ".gi${u200c}t" >tree &&
58+
ok=$(git mktree <tree) &&
59+
git read-tree $ok
60+
'
61+
62+
test_done

t/t1450-fsck.sh

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -251,35 +251,40 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' '
251251
)
252252
'
253253

254-
test_expect_success 'fsck notices "." and ".." in trees' '
255-
(
256-
git init dots &&
257-
cd dots &&
258-
blob=$(echo foo | git hash-object -w --stdin) &&
259-
tab=$(printf "\\t") &&
260-
git mktree <<-EOF &&
261-
100644 blob $blob$tab.
262-
100644 blob $blob$tab..
263-
EOF
264-
git fsck 2>out &&
265-
cat out &&
266-
grep "warning.*\\." out
267-
)
268-
'
269-
270-
test_expect_success 'fsck notices ".git" in trees' '
271-
(
272-
git init dotgit &&
273-
cd dotgit &&
274-
blob=$(echo foo | git hash-object -w --stdin) &&
275-
tab=$(printf "\\t") &&
276-
git mktree <<-EOF &&
277-
100644 blob $blob$tab.git
278-
EOF
279-
git fsck 2>out &&
280-
cat out &&
281-
grep "warning.*\\.git" out
282-
)
283-
'
254+
while read name path pretty; do
255+
while read mode type; do
256+
: ${pretty:=$path}
257+
test_expect_success "fsck notices $pretty as $type" '
258+
(
259+
git init $name-$type &&
260+
cd $name-$type &&
261+
echo content >file &&
262+
git add file &&
263+
git commit -m base &&
264+
blob=$(git rev-parse :file) &&
265+
tree=$(git rev-parse HEAD^{tree}) &&
266+
value=$(eval "echo \$$type") &&
267+
printf "$mode $type %s\t%s" "$value" "$path" >bad &&
268+
bad_tree=$(git mktree <bad) &&
269+
git fsck 2>out &&
270+
cat out &&
271+
grep "warning.*tree $bad_tree" out
272+
)'
273+
done <<-\EOF
274+
100644 blob
275+
040000 tree
276+
EOF
277+
done <<-EOF
278+
dot .
279+
dotdot ..
280+
dotgit .git
281+
dotgit-case .GIT
282+
dotgit-unicode .gI${u200c}T .gI{u200c}T
283+
dotgit-case2 .Git
284+
git-tilde1 git~1
285+
dotgitdot .git.
286+
dot-backslash-case .\\\\.GIT\\\\foobar
287+
dotgit-case-backslash .git\\\\foobar
288+
EOF
284289

285290
test_done

t/test-lib.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ _z40=0000000000000000000000000000000000000000
158158
LF='
159159
'
160160

161-
export _x05 _x40 _z40 LF
161+
# UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
162+
# when case-folding filenames
163+
u200c=$(printf '\342\200\214')
164+
165+
export _x05 _x40 _z40 LF u200c
162166

163167
# Each test should start with something like this, after copyright notices:
164168
#

0 commit comments

Comments
 (0)