Skip to content

Commit a9b0b6d

Browse files
committed
Merge branch 'forward-port/jk/ssh-funny-url'
This topic branch brings a critical bug fix to the Git for Windows v2.13.1 "maintenance track". Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 7723f38 + aa922b8 commit a9b0b6d

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

cache.h

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

1116+
/*
1117+
* Returns true iff "str" could be confused as a command-line option when
1118+
* passed to a sub-program like "ssh". Note that this has nothing to do with
1119+
* shell-quoting, which should be handled separately; we're assuming here that
1120+
* the string makes it verbatim to the sub-program.
1121+
*/
1122+
int looks_like_command_line_option(const char *str);
1123+
11161124
/**
11171125
* Return a newly allocated string with the evaluation of
11181126
* "$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);
@@ -802,6 +807,9 @@ struct child_process *git_connect(int fd[2], const char *url,
802807
conn = xmalloc(sizeof(*conn));
803808
child_process_init(conn);
804809

810+
if (looks_like_command_line_option(path))
811+
die("strange pathname '%s' blocked", path);
812+
805813
strbuf_addstr(&cmd, prog);
806814
strbuf_addch(&cmd, ' ');
807815
sq_quote_buf(&cmd, path);
@@ -835,6 +843,9 @@ struct child_process *git_connect(int fd[2], const char *url,
835843
return NULL;
836844
}
837845

846+
if (looks_like_command_line_option(ssh_host))
847+
die("strange hostname '%s' blocked", ssh_host);
848+
838849
ssh = get_ssh_command();
839850
if (ssh)
840851
handle_ssh_variant(ssh, 1, &port_option,

path.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,11 @@ int is_ntfs_dotgit(const char *name)
12621262
}
12631263
}
12641264

1265+
int looks_like_command_line_option(const char *str)
1266+
{
1267+
return str && str[0] == '-';
1268+
}
1269+
12651270
char *xdg_config_home(const char *filename)
12661271
{
12671272
const char *home, *config_home;

t/lib-proto-disable.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ test_config () {
172172
rm -rf tmp.git &&
173173
test_must_fail git clone --bare "$url" tmp.git
174174
'
175+
176+
test_expect_success 'unset protocol.allow' '
177+
git config --global --unset protocol.allow
178+
'
175179
}
176180

177181
# test cloning a particular protocol

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)