Skip to content

Commit 05bb78a

Browse files
committed
Merge tag 'v2.10.4' into maint-2.11
Git 2.10.4
2 parents 773e3a2 + 0bfff81 commit 05bb78a

File tree

10 files changed

+112
-0
lines changed

10 files changed

+112
-0
lines changed

Documentation/RelNotes/2.10.4.txt

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

Documentation/RelNotes/2.7.6.txt

Lines changed: 25 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
11081108
int daemon_avoid_alias(const char *path);
11091109
extern int is_ntfs_dotgit(const char *name);
11101110

1111+
/*
1112+
* Returns true iff "str" could be confused as a command-line option when
1113+
* passed to a sub-program like "ssh". Note that this has nothing to do with
1114+
* shell-quoting, which should be handled separately; we're assuming here that
1115+
* the string makes it verbatim to the sub-program.
1116+
*/
1117+
int looks_like_command_line_option(const char *str);
1118+
11111119
/**
11121120
* Return a newly allocated string with the evaluation of
11131121
* "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise

connect.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,11 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
577577

578578
get_host_and_port(&host, &port);
579579

580+
if (looks_like_command_line_option(host))
581+
die("strange hostname '%s' blocked", host);
582+
if (looks_like_command_line_option(port))
583+
die("strange port '%s' blocked", port);
584+
580585
proxy = xmalloc(sizeof(*proxy));
581586
child_process_init(proxy);
582587
argv_array_push(&proxy->args, git_proxy_command);
@@ -759,6 +764,9 @@ struct child_process *git_connect(int fd[2], const char *url,
759764
conn = xmalloc(sizeof(*conn));
760765
child_process_init(conn);
761766

767+
if (looks_like_command_line_option(path))
768+
die("strange pathname '%s' blocked", path);
769+
762770
strbuf_addstr(&cmd, prog);
763771
strbuf_addch(&cmd, ' ');
764772
sq_quote_buf(&cmd, path);
@@ -791,6 +799,9 @@ struct child_process *git_connect(int fd[2], const char *url,
791799
return NULL;
792800
}
793801

802+
if (looks_like_command_line_option(ssh_host))
803+
die("strange hostname '%s' blocked", ssh_host);
804+
794805
ssh = get_ssh_command();
795806
if (!ssh) {
796807
const char *base;

path.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,11 @@ int is_ntfs_dotgit(const char *name)
12571257
}
12581258
}
12591259

1260+
int looks_like_command_line_option(const char *str)
1261+
{
1262+
return str && str[0] == '-';
1263+
}
1264+
12601265
char *xdg_config_home(const char *filename)
12611266
{
12621267
const char *home, *config_home;

t/t5532-fetch-proxy.sh

Lines changed: 5 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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)