]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Windows: do not treat a path with backslashes as a remote's nick name
authorJohannes Sixt <j6t@kdbg.org>
Thu, 25 May 2017 12:00:13 +0000 (14:00 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 May 2017 23:05:32 +0000 (08:05 +0900)
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 <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c

index ad6c5424edab2ae15ac17bfcf12ac4ee93b5aa3f..1949882c10a05a1f53b711f6cd3f3e083ca27393 100644 (file)
--- 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)