Skip to content

Commit 402f63a

Browse files
lrm29ethomson
authored andcommitted
Return an error for invalid proxy URLs instead of crashing.
1 parent 0ddc077 commit 402f63a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/libgit2/transports/http.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,19 @@ static int lookup_proxy(
334334
return 0;
335335
}
336336

337-
if (!proxy ||
338-
(error = git_net_url_parse(&transport->proxy.url, proxy)) < 0)
337+
if (!proxy)
339338
goto done;
340339

340+
341+
if ((error = git_net_url_parse(&transport->proxy.url, proxy) < 0))
342+
goto done;
343+
344+
if (!git_net_url_valid(&transport->proxy.url)) {
345+
git_error_set(GIT_ERROR_HTTP, "invalid proxy url: %s", proxy);
346+
error = GIT_EINVALIDSPEC;
347+
goto done;
348+
}
349+
341350
*out_use = true;
342351

343352
done:

tests/libgit2/online/clone.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,19 @@ static int proxy_cert_cb(git_cert *cert, int valid, const char *host, void *payl
968968
return valid ? 0 : GIT_ECERTIFICATE;
969969
}
970970

971+
void test_online_clone__proxy_invalid_url(void)
972+
{
973+
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
974+
g_options.fetch_opts.proxy_opts.credentials = proxy_cred_cb;
975+
g_options.fetch_opts.proxy_opts.certificate_check = proxy_cert_cb;
976+
977+
g_options.fetch_opts.proxy_opts.url = "noschemeorport";
978+
cl_git_fail_with(GIT_EINVALIDSPEC, git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
979+
980+
g_options.fetch_opts.proxy_opts.url = "noscheme:8080";
981+
cl_git_fail_with(GIT_EINVALIDSPEC, git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
982+
}
983+
971984
void test_online_clone__proxy_credentials_request(void)
972985
{
973986
git_str url = GIT_STR_INIT;

0 commit comments

Comments
 (0)