Skip to content

Commit d63ed6e

Browse files
peffgitster
authored andcommitted
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 372370f (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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0b65a8d commit d63ed6e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ static CURL *get_curl_handle(void)
590590
* precedence here, as in CURL.
591591
*/
592592
if (!curl_http_proxy) {
593-
if (!strcmp(http_auth.protocol, "https")) {
593+
if (http_auth.protocol && !strcmp(http_auth.protocol, "https")) {
594594
var_override(&curl_http_proxy, getenv("HTTPS_PROXY"));
595595
var_override(&curl_http_proxy, getenv("https_proxy"));
596596
} else {

t/t5550-http-fetch-dumb.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,13 @@ test_expect_success 'git client does not send an empty Accept-Language' '
250250
! grep "^Accept-Language:" stderr
251251
'
252252

253+
test_expect_success 'remote-http complains cleanly about malformed urls' '
254+
# do not actually issue "list" or other commands, as we do not
255+
# want to rely on what curl would actually do with such a broken
256+
# URL. This is just about making sure we do not segfault during
257+
# initialization.
258+
test_must_fail git remote-http http::/example.com/repo.git
259+
'
260+
253261
stop_httpd
254262
test_done

0 commit comments

Comments
 (0)