Blame SOURCES/git-cve-2017-1000117.patch

fdd391
diff --git a/cache.h b/cache.h
fdd391
index 94ca1ac..2ab9ffd 100644
fdd391
--- a/cache.h
fdd391
+++ b/cache.h
fdd391
@@ -744,6 +744,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
fdd391
 int daemon_avoid_alias(const char *path);
fdd391
 int offset_1st_component(const char *path);
fdd391
 
fdd391
+/*
fdd391
+ * Returns true iff "str" could be confused as a command-line option when
fdd391
+ * passed to a sub-program like "ssh". Note that this has nothing to do with
fdd391
+ * shell-quoting, which should be handled separately; we're assuming here that
fdd391
+ * the string makes it verbatim to the sub-program.
fdd391
+ */
fdd391
+int looks_like_command_line_option(const char *str);
fdd391
+
fdd391
 /* object replacement */
fdd391
 #define READ_SHA1_FILE_REPLACE 1
fdd391
 extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
fdd391
diff --git a/connect.c b/connect.c
fdd391
index 6d4ea13..970f565 100644
fdd391
--- a/connect.c
fdd391
+++ b/connect.c
fdd391
@@ -450,6 +450,11 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
fdd391
 
fdd391
 	get_host_and_port(&host, &port);
fdd391
 
fdd391
+	if (looks_like_command_line_option(host))
fdd391
+		die("strange hostname '%s' blocked", host);
fdd391
+	if (looks_like_command_line_option(port))
fdd391
+		die("strange port '%s' blocked", port);
fdd391
+
fdd391
 	argv = xmalloc(sizeof(*argv) * 4);
fdd391
 	argv[0] = git_proxy_command;
fdd391
 	argv[1] = host;
fdd391
@@ -613,6 +618,10 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
fdd391
 
fdd391
 	conn = xcalloc(1, sizeof(*conn));
fdd391
 
fdd391
+	if (looks_like_command_line_option(path))
fdd391
+		die("strange pathname '%s' blocked", path);
fdd391
+
fdd391
+
fdd391
 	strbuf_init(&cmd, MAX_CMD_LEN);
fdd391
 	strbuf_addstr(&cmd, prog);
fdd391
 	strbuf_addch(&cmd, ' ');
fdd391
@@ -626,6 +635,10 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
fdd391
 		const char *ssh = getenv("GIT_SSH");
fdd391
 		int putty = ssh && strcasestr(ssh, "plink");
fdd391
 		transport_check_allowed("ssh");
fdd391
+		if (looks_like_command_line_option(host))
fdd391
+			die("strange hostname '%s' blocked", host);
fdd391
+
fdd391
+
fdd391
 		if (!ssh) ssh = "ssh";
fdd391
 
fdd391
 		*arg++ = ssh;
fdd391
diff --git a/path.c b/path.c
fdd391
index 04ff148..713d79b 100644
fdd391
--- a/path.c
fdd391
+++ b/path.c
fdd391
@@ -701,3 +701,9 @@ int offset_1st_component(const char *path)
fdd391
 		return 2 + is_dir_sep(path[2]);
fdd391
 	return is_dir_sep(path[0]);
fdd391
 }
fdd391
+
fdd391
+int looks_like_command_line_option(const char *str)
fdd391
+{
fdd391
+	return str && str[0] == '-';
fdd391
+}
fdd391
+
fdd391
diff --git a/t/t5532-fetch-proxy.sh b/t/t5532-fetch-proxy.sh
fdd391
index 5531bd1..d3b2651 100755
fdd391
--- a/t/t5532-fetch-proxy.sh
fdd391
+++ b/t/t5532-fetch-proxy.sh
fdd391
@@ -40,4 +40,9 @@ test_expect_success 'fetch through proxy works' '
fdd391
 	test_cmp expect actual
fdd391
 '
fdd391
 
fdd391
+test_expect_success 'funny hostnames are rejected before running proxy' '
fdd391
+	test_must_fail git fetch git://-remote/repo.git 2>stderr &&
fdd391
+	! grep "proxying for" stderr
fdd391
+'
fdd391
+
fdd391
 test_done