Skip to content

Commit e312af1

Browse files
committed
Merge tag 'v2.12.4' into maint
2 parents cf8899d + 3d9c5b5 commit e312af1

13 files changed

+126
-2
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.11.3.txt

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

Documentation/RelNotes/2.12.4.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Git v2.12.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
@@ -1190,6 +1190,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
11901190
int daemon_avoid_alias(const char *path);
11911191
extern int is_ntfs_dotgit(const char *name);
11921192

1193+
/*
1194+
* Returns true iff "str" could be confused as a command-line option when
1195+
* passed to a sub-program like "ssh". Note that this has nothing to do with
1196+
* shell-quoting, which should be handled separately; we're assuming here that
1197+
* the string makes it verbatim to the sub-program.
1198+
*/
1199+
int looks_like_command_line_option(const char *str);
1200+
11931201
/**
11941202
* Return a newly allocated string with the evaluation of
11951203
* "$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);
@@ -823,6 +828,9 @@ struct child_process *git_connect(int fd[2], const char *url,
823828
conn = xmalloc(sizeof(*conn));
824829
child_process_init(conn);
825830

831+
if (looks_like_command_line_option(path))
832+
die("strange pathname '%s' blocked", path);
833+
826834
strbuf_addstr(&cmd, prog);
827835
strbuf_addch(&cmd, ' ');
828836
sq_quote_buf(&cmd, path);
@@ -856,6 +864,9 @@ struct child_process *git_connect(int fd[2], const char *url,
856864
return NULL;
857865
}
858866

867+
if (looks_like_command_line_option(ssh_host))
868+
die("strange hostname '%s' blocked", ssh_host);
869+
859870
ssh = get_ssh_command();
860871
if (ssh)
861872
handle_ssh_variant(ssh, 1, &port_option,

path.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,11 @@ int is_ntfs_dotgit(const char *name)
12411241
}
12421242
}
12431243

1244+
int looks_like_command_line_option(const char *str)
1245+
{
1246+
return str && str[0] == '-';
1247+
}
1248+
12441249
char *xdg_config_home(const char *filename)
12451250
{
12461251
const char *home, *config_home;

t/lib-proto-disable.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,33 @@ test_config () {
147147
# Test clone/fetch/push with protocol.allow user defined default
148148
test_expect_success "clone $desc (enabled)" '
149149
rm -rf tmp.git &&
150-
git config --global protocol.allow always &&
150+
test_config_global protocol.allow always &&
151151
git clone --bare "$url" tmp.git
152152
'
153153

154154
test_expect_success "fetch $desc (enabled)" '
155+
test_config_global protocol.allow always &&
155156
git -C tmp.git fetch
156157
'
157158

158159
test_expect_success "push $desc (enabled)" '
160+
test_config_global protocol.allow always &&
159161
git -C tmp.git push origin HEAD:pushed
160162
'
161163

162164
test_expect_success "push $desc (disabled)" '
163-
git config --global protocol.allow never &&
165+
test_config_global protocol.allow never &&
164166
test_must_fail git -C tmp.git push origin HEAD:pushed
165167
'
166168

167169
test_expect_success "fetch $desc (disabled)" '
170+
test_config_global protocol.allow never &&
168171
test_must_fail git -C tmp.git fetch
169172
'
170173

171174
test_expect_success "clone $desc (disabled)" '
172175
rm -rf tmp.git &&
176+
test_config_global protocol.allow never &&
173177
test_must_fail git clone --bare "$url" tmp.git
174178
'
175179
}

0 commit comments

Comments
 (0)