From e20b5b59099a960d59f20276ae37353870e714de Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 22 May 2017 20:58:32 +0200 Subject: [PATCH 1/2] mingw.h: permit arguments with side effects for is_dir_sep Taking git-compat-util.h's cue (which uses an inline function to back is_dir_sep()), let's use an inline function to back also the Windows version of is_dir_sep(). This avoids problems when calling the function with arguments that do more than just provide a single character, e.g. incrementing a pointer. Example: is_dir_sep(*p++) Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- compat/mingw.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compat/mingw.h b/compat/mingw.h index 034fff9479..d2168c1e5e 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -395,7 +395,11 @@ HANDLE winansi_get_osfhandle(int fd); (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0) int mingw_skip_dos_drive_prefix(char **path); #define skip_dos_drive_prefix mingw_skip_dos_drive_prefix -#define is_dir_sep(c) ((c) == '/' || (c) == '\\') +static inline int mingw_is_dir_sep(int c) +{ + return c == '/' || c == '\\'; +} +#define is_dir_sep mingw_is_dir_sep static inline char *mingw_find_last_dir_sep(const char *path) { char *ret = NULL; From d9244ecf4f109030e61b8fd52a799789133e2199 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Thu, 25 May 2017 14:00:13 +0200 Subject: [PATCH 2/2] Windows: do not treat a path with backslashes as a remote's nick name On Windows, the remote repository name in, e.g., `git fetch foo\bar` is clearly not a nickname for a configured remote repository. However, the function valid_remote_nick() does not account for backslashes. Use is_dir_sep() to check for both slashes and backslashes on Windows. This was discovered while playing with Duy's patches that warn after fopen() failures. The functions that read the branches and remotes files are protected by a valid_remote_nick() check. Without this change, a Windows style absolute path is incorrectly regarded as nickname and is concatenated to a prefix and used with fopen(). This triggers warnings because a colon in a path name is not allowed: C:\Temp\gittest>git fetch C:\Temp\gittest warning: unable to access '.git/remotes/C:\Temp\gittest': Invalid argument warning: unable to access '.git/branches/C:\Temp\gittest': Invalid argument From C:\Temp\gittest * branch HEAD -> FETCH_HEAD Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- remote.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/remote.c b/remote.c index ad6c5424ed..1949882c10 100644 --- a/remote.c +++ b/remote.c @@ -645,7 +645,12 @@ static int valid_remote_nick(const char *name) { if (!name[0] || is_dot_or_dotdot(name)) return 0; - return !strchr(name, '/'); /* no slash */ + + /* remote nicknames cannot contain slashes */ + while (*name) + if (is_dir_sep(*name++)) + return 0; + return 1; } const char *remote_for_branch(struct branch *branch, int *explicit)