Skip to content

Commit d78f06a

Browse files
committedJul 30, 2017
Merge tag 'v2.9.5' into maint-2.10
Git 2.9.5
2 parents 840ed14 + 4d4165b commit d78f06a

9 files changed

+108
-0
lines changed
 

‎Documentation/RelNotes/2.7.6.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Git v2.7.6 Release Notes
2+
========================
3+
4+
Fixes since v2.7.5
5+
------------------
6+
7+
* A "ssh://..." URL can result in a "ssh" command line with a
8+
hostname that begins with a dash "-", which would cause the "ssh"
9+
command to instead (mis)treat it as an option. This is now
10+
prevented by forbidding such a hostname (which will not be
11+
necessary in the real world).
12+
13+
* Similarly, when GIT_PROXY_COMMAND is configured, the command is
14+
run with host and port that are parsed out from "ssh://..." URL;
15+
a poorly written GIT_PROXY_COMMAND could be tricked into treating
16+
a string that begins with a dash "-". This is now prevented by
17+
forbidding such a hostname and port number (again, which will not
18+
be necessary in the real world).
19+
20+
* In the same spirit, a repository name that begins with a dash "-"
21+
is also forbidden now.
22+
23+
Credits go to Brian Neel at GitLab, Joern Schneeweisz of Recurity
24+
Labs and Jeff King at GitHub.
25+

‎Documentation/RelNotes/2.8.6.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Git v2.8.6 Release Notes
2+
========================
3+
4+
This release forward-ports the fix for "ssh://..." URL from Git v2.7.6

‎Documentation/RelNotes/2.9.5.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Git v2.9.5 Release Notes
2+
========================
3+
4+
This release forward-ports the fix for "ssh://..." URL from Git v2.7.6

‎cache.h

+8
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
10421042
int daemon_avoid_alias(const char *path);
10431043
extern int is_ntfs_dotgit(const char *name);
10441044

1045+
/*
1046+
* Returns true iff "str" could be confused as a command-line option when
1047+
* passed to a sub-program like "ssh". Note that this has nothing to do with
1048+
* shell-quoting, which should be handled separately; we're assuming here that
1049+
* the string makes it verbatim to the sub-program.
1050+
*/
1051+
int looks_like_command_line_option(const char *str);
1052+
10451053
/**
10461054
* Return a newly allocated string with the evaluation of
10471055
* "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise

‎connect.c

+11
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
557557

558558
get_host_and_port(&host, &port);
559559

560+
if (looks_like_command_line_option(host))
561+
die("strange hostname '%s' blocked", host);
562+
if (looks_like_command_line_option(port))
563+
die("strange port '%s' blocked", port);
564+
560565
proxy = xmalloc(sizeof(*proxy));
561566
child_process_init(proxy);
562567
argv_array_push(&proxy->args, git_proxy_command);
@@ -739,6 +744,9 @@ struct child_process *git_connect(int fd[2], const char *url,
739744
conn = xmalloc(sizeof(*conn));
740745
child_process_init(conn);
741746

747+
if (looks_like_command_line_option(path))
748+
die("strange pathname '%s' blocked", path);
749+
742750
strbuf_addstr(&cmd, prog);
743751
strbuf_addch(&cmd, ' ');
744752
sq_quote_buf(&cmd, path);
@@ -771,6 +779,9 @@ struct child_process *git_connect(int fd[2], const char *url,
771779
return NULL;
772780
}
773781

782+
if (looks_like_command_line_option(ssh_host))
783+
die("strange hostname '%s' blocked", ssh_host);
784+
774785
ssh = get_ssh_command();
775786
if (!ssh) {
776787
const char *base;

‎path.c

+5
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,11 @@ int is_ntfs_dotgit(const char *name)
12251225
}
12261226
}
12271227

1228+
int looks_like_command_line_option(const char *str)
1229+
{
1230+
return str && str[0] == '-';
1231+
}
1232+
12281233
char *xdg_config_home(const char *filename)
12291234
{
12301235
const char *home, *config_home;

‎t/t5532-fetch-proxy.sh

+5
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ test_expect_success 'fetch through proxy works' '
4343
test_cmp expect actual
4444
'
4545

46+
test_expect_success 'funny hostnames are rejected before running proxy' '
47+
test_must_fail git fetch git://-remote/repo.git 2>stderr &&
48+
! grep "proxying for" stderr
49+
'
50+
4651
test_done

‎t/t5810-proto-disable-local.sh

+23
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,27 @@ test_expect_success 'setup repository to clone' '
1111
test_proto "file://" file "file://$PWD"
1212
test_proto "path" file .
1313

14+
test_expect_success 'setup repo with dash' '
15+
git init --bare repo.git &&
16+
git push repo.git HEAD &&
17+
mv repo.git "$PWD/-repo.git"
18+
'
19+
20+
# This will fail even without our rejection because upload-pack will
21+
# complain about the bogus option. So let's make sure that GIT_TRACE
22+
# doesn't show us even running upload-pack.
23+
#
24+
# We must also be sure to use "fetch" and not "clone" here, as the latter
25+
# actually canonicalizes our input into an absolute path (which is fine
26+
# to allow).
27+
test_expect_success 'repo names starting with dash are rejected' '
28+
rm -f trace.out &&
29+
test_must_fail env GIT_TRACE="$PWD/trace.out" git fetch -- -repo.git &&
30+
! grep upload-pack trace.out
31+
'
32+
33+
test_expect_success 'full paths still work' '
34+
git fetch "$PWD/-repo.git"
35+
'
36+
1437
test_done

‎t/t5813-proto-disable-ssh.sh

+23
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,27 @@ test_proto "host:path" ssh "remote:repo.git"
1717
test_proto "ssh://" ssh "ssh://remote$PWD/remote/repo.git"
1818
test_proto "git+ssh://" ssh "git+ssh://remote$PWD/remote/repo.git"
1919

20+
# Don't even bother setting up a "-remote" directory, as ssh would generally
21+
# complain about the bogus option rather than completing our request. Our
22+
# fake wrapper actually _can_ handle this case, but it's more robust to
23+
# simply confirm from its output that it did not run at all.
24+
test_expect_success 'hostnames starting with dash are rejected' '
25+
test_must_fail git clone ssh://-remote/repo.git dash-host 2>stderr &&
26+
! grep ^ssh: stderr
27+
'
28+
29+
test_expect_success 'setup repo with dash' '
30+
git init --bare remote/-repo.git &&
31+
git push remote/-repo.git HEAD
32+
'
33+
34+
test_expect_success 'repo names starting with dash are rejected' '
35+
test_must_fail git clone remote:-repo.git dash-path 2>stderr &&
36+
! grep ^ssh: stderr
37+
'
38+
39+
test_expect_success 'full paths still work' '
40+
git clone "remote:$PWD/remote/-repo.git" dash-path
41+
'
42+
2043
test_done

0 commit comments

Comments
 (0)
Please sign in to comment.