Skip to content

Commit dd53ea7

Browse files
committed
Merge branch 'turn-on-protectntfs-by-default'
This patch series makes it safe to use Git on Windows drives, even if running on a mounted network share or within the Windows Subsystem for Linux (WSL). This topic branch addresses CVE-2019-1353. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 7f3551d + 9102f95 commit dd53ea7

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

config.mak.uname

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ ifeq ($(uname_S),Windows)
379379
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj
380380
PTHREAD_LIBS =
381381
lib =
382-
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
383382
ifndef DEBUG
384383
BASIC_CFLAGS += -GL -Os -MD
385384
BASIC_LDFLAGS += -LTCG
@@ -516,7 +515,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
516515
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
517516
compat/win32/pthread.o compat/win32/syslog.o \
518517
compat/win32/dirent.o
519-
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
520518
EXTLIBS += -lws2_32
521519
GITLIBS += git.res
522520
PTHREAD_LIBS =

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
7373
int protect_hfs = PROTECT_HFS_DEFAULT;
7474

7575
#ifndef PROTECT_NTFS_DEFAULT
76-
#define PROTECT_NTFS_DEFAULT 0
76+
#define PROTECT_NTFS_DEFAULT 1
7777
#endif
7878
int protect_ntfs = PROTECT_NTFS_DEFAULT;
7979

path.c

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,20 +1288,6 @@ int daemon_avoid_alias(const char *p)
12881288
}
12891289
}
12901290

1291-
static int only_spaces_and_periods(const char *path, size_t len, size_t skip)
1292-
{
1293-
if (len < skip)
1294-
return 0;
1295-
len -= skip;
1296-
path += skip;
1297-
while (len-- > 0) {
1298-
char c = *(path++);
1299-
if (c != ' ' && c != '.')
1300-
return 0;
1301-
}
1302-
return 1;
1303-
}
1304-
13051291
/*
13061292
* On NTFS, we need to be careful to disallow certain synonyms of the `.git/`
13071293
* directory:
@@ -1341,19 +1327,38 @@ static int only_spaces_and_periods(const char *path, size_t len, size_t skip)
13411327
*/
13421328
int is_ntfs_dotgit(const char *name)
13431329
{
1344-
size_t len;
1330+
char c;
13451331

1346-
for (len = 0; ; len++)
1347-
if (!name[len] || name[len] == '\\' || is_dir_sep(name[len]) ||
1348-
name[len] == ':') {
1349-
if (only_spaces_and_periods(name, len, 4) &&
1350-
!strncasecmp(name, ".git", 4))
1351-
return 1;
1352-
if (only_spaces_and_periods(name, len, 5) &&
1353-
!strncasecmp(name, "git~1", 5))
1354-
return 1;
1332+
/*
1333+
* Note that when we don't find `.git` or `git~1` we end up with `name`
1334+
* advanced partway through the string. That's okay, though, as we
1335+
* return immediately in those cases, without looking at `name` any
1336+
* further.
1337+
*/
1338+
c = *(name++);
1339+
if (c == '.') {
1340+
/* .git */
1341+
if (((c = *(name++)) != 'g' && c != 'G') ||
1342+
((c = *(name++)) != 'i' && c != 'I') ||
1343+
((c = *(name++)) != 't' && c != 'T'))
13551344
return 0;
1356-
}
1345+
} else if (c == 'g' || c == 'G') {
1346+
/* git ~1 */
1347+
if (((c = *(name++)) != 'i' && c != 'I') ||
1348+
((c = *(name++)) != 't' && c != 'T') ||
1349+
*(name++) != '~' ||
1350+
*(name++) != '1')
1351+
return 0;
1352+
} else
1353+
return 0;
1354+
1355+
for (;;) {
1356+
c = *(name++);
1357+
if (!c || c == '\\' || c == '/' || c == ':')
1358+
return 1;
1359+
if (c != '.' && c != ' ')
1360+
return 0;
1361+
}
13571362
}
13581363

13591364
static int is_ntfs_dot_generic(const char *name,

0 commit comments

Comments
 (0)