提交 d63ed6ef 编写于 作者: J Jeff King 提交者: Junio C Hamano

remote-curl: handle URLs without protocol

Generally remote-curl would never see a URL that did not
have "proto:" at the beginning, as that is what tells git to
run the "git-remote-proto" helper (and git-remote-http, etc,
are aliases for git-remote-curl).

However, the special syntax "proto::something" will run
git-remote-proto with only "something" as the URL. So a
malformed URL like:

  http::/example.com/repo.git

will feed the URL "/example.com/repo.git" to
git-remote-http. The resulting URL has no protocol, but the
code added by 372370f1 (http: use credential API to handle
proxy authentication, 2016-01-26) does not handle this case
and segfaults.

For the purposes of this code, we don't really care what the
exact protocol; only whether or not it is https. So let's
just assume that a missing protocol is not, and curl will
handle the real error (which is that the URL is nonsense).
Signed-off-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 0b65a8db
...@@ -590,7 +590,7 @@ static CURL *get_curl_handle(void) ...@@ -590,7 +590,7 @@ static CURL *get_curl_handle(void)
* precedence here, as in CURL. * precedence here, as in CURL.
*/ */
if (!curl_http_proxy) { if (!curl_http_proxy) {
if (!strcmp(http_auth.protocol, "https")) { if (http_auth.protocol && !strcmp(http_auth.protocol, "https")) {
var_override(&curl_http_proxy, getenv("HTTPS_PROXY")); var_override(&curl_http_proxy, getenv("HTTPS_PROXY"));
var_override(&curl_http_proxy, getenv("https_proxy")); var_override(&curl_http_proxy, getenv("https_proxy"));
} else { } else {
......
...@@ -250,5 +250,13 @@ test_expect_success 'git client does not send an empty Accept-Language' ' ...@@ -250,5 +250,13 @@ test_expect_success 'git client does not send an empty Accept-Language' '
! grep "^Accept-Language:" stderr ! grep "^Accept-Language:" stderr
' '
test_expect_success 'remote-http complains cleanly about malformed urls' '
# do not actually issue "list" or other commands, as we do not
# want to rely on what curl would actually do with such a broken
# URL. This is just about making sure we do not segfault during
# initialization.
test_must_fail git remote-http http::/example.com/repo.git
'
stop_httpd stop_httpd
test_done test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册