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 <johannes.schindelin@gmx.de>
This commit is contained in:
commit
dd53ea7220
@ -379,7 +379,6 @@ ifeq ($(uname_S),Windows)
|
|||||||
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj
|
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj
|
||||||
PTHREAD_LIBS =
|
PTHREAD_LIBS =
|
||||||
lib =
|
lib =
|
||||||
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
|
|
||||||
ifndef DEBUG
|
ifndef DEBUG
|
||||||
BASIC_CFLAGS += -GL -Os -MD
|
BASIC_CFLAGS += -GL -Os -MD
|
||||||
BASIC_LDFLAGS += -LTCG
|
BASIC_LDFLAGS += -LTCG
|
||||||
@ -516,7 +515,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
|
|||||||
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
|
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
|
||||||
compat/win32/pthread.o compat/win32/syslog.o \
|
compat/win32/pthread.o compat/win32/syslog.o \
|
||||||
compat/win32/dirent.o
|
compat/win32/dirent.o
|
||||||
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
|
|
||||||
EXTLIBS += -lws2_32
|
EXTLIBS += -lws2_32
|
||||||
GITLIBS += git.res
|
GITLIBS += git.res
|
||||||
PTHREAD_LIBS =
|
PTHREAD_LIBS =
|
||||||
|
@ -73,7 +73,7 @@ enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
|
|||||||
int protect_hfs = PROTECT_HFS_DEFAULT;
|
int protect_hfs = PROTECT_HFS_DEFAULT;
|
||||||
|
|
||||||
#ifndef PROTECT_NTFS_DEFAULT
|
#ifndef PROTECT_NTFS_DEFAULT
|
||||||
#define PROTECT_NTFS_DEFAULT 0
|
#define PROTECT_NTFS_DEFAULT 1
|
||||||
#endif
|
#endif
|
||||||
int protect_ntfs = PROTECT_NTFS_DEFAULT;
|
int protect_ntfs = PROTECT_NTFS_DEFAULT;
|
||||||
|
|
||||||
|
55
path.c
55
path.c
@ -1288,20 +1288,6 @@ int daemon_avoid_alias(const char *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int only_spaces_and_periods(const char *path, size_t len, size_t skip)
|
|
||||||
{
|
|
||||||
if (len < skip)
|
|
||||||
return 0;
|
|
||||||
len -= skip;
|
|
||||||
path += skip;
|
|
||||||
while (len-- > 0) {
|
|
||||||
char c = *(path++);
|
|
||||||
if (c != ' ' && c != '.')
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On NTFS, we need to be careful to disallow certain synonyms of the `.git/`
|
* On NTFS, we need to be careful to disallow certain synonyms of the `.git/`
|
||||||
* directory:
|
* directory:
|
||||||
@ -1341,19 +1327,38 @@ static int only_spaces_and_periods(const char *path, size_t len, size_t skip)
|
|||||||
*/
|
*/
|
||||||
int is_ntfs_dotgit(const char *name)
|
int is_ntfs_dotgit(const char *name)
|
||||||
{
|
{
|
||||||
size_t len;
|
char c;
|
||||||
|
|
||||||
for (len = 0; ; len++)
|
/*
|
||||||
if (!name[len] || name[len] == '\\' || is_dir_sep(name[len]) ||
|
* Note that when we don't find `.git` or `git~1` we end up with `name`
|
||||||
name[len] == ':') {
|
* advanced partway through the string. That's okay, though, as we
|
||||||
if (only_spaces_and_periods(name, len, 4) &&
|
* return immediately in those cases, without looking at `name` any
|
||||||
!strncasecmp(name, ".git", 4))
|
* further.
|
||||||
return 1;
|
*/
|
||||||
if (only_spaces_and_periods(name, len, 5) &&
|
c = *(name++);
|
||||||
!strncasecmp(name, "git~1", 5))
|
if (c == '.') {
|
||||||
return 1;
|
/* .git */
|
||||||
|
if (((c = *(name++)) != 'g' && c != 'G') ||
|
||||||
|
((c = *(name++)) != 'i' && c != 'I') ||
|
||||||
|
((c = *(name++)) != 't' && c != 'T'))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (c == 'g' || c == 'G') {
|
||||||
|
/* git ~1 */
|
||||||
|
if (((c = *(name++)) != 'i' && c != 'I') ||
|
||||||
|
((c = *(name++)) != 't' && c != 'T') ||
|
||||||
|
*(name++) != '~' ||
|
||||||
|
*(name++) != '1')
|
||||||
|
return 0;
|
||||||
|
} else
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
c = *(name++);
|
||||||
|
if (!c || c == '\\' || c == '/' || c == ':')
|
||||||
|
return 1;
|
||||||
|
if (c != '.' && c != ' ')
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_ntfs_dot_generic(const char *name,
|
static int is_ntfs_dot_generic(const char *name,
|
||||||
|
Loading…
Reference in New Issue
Block a user