Commit 402f63a4 by lmcglash Committed by Edward Thomson

Return an error for invalid proxy URLs instead of crashing.

parent 0ddc0776
...@@ -334,10 +334,19 @@ static int lookup_proxy( ...@@ -334,10 +334,19 @@ static int lookup_proxy(
return 0; return 0;
} }
if (!proxy || if (!proxy)
(error = git_net_url_parse(&transport->proxy.url, proxy)) < 0)
goto done; goto done;
if ((error = git_net_url_parse(&transport->proxy.url, proxy) < 0))
goto done;
if (!git_net_url_valid(&transport->proxy.url)) {
git_error_set(GIT_ERROR_HTTP, "invalid proxy url: %s", proxy);
error = GIT_EINVALIDSPEC;
goto done;
}
*out_use = true; *out_use = true;
done: done:
......
...@@ -968,6 +968,19 @@ static int proxy_cert_cb(git_cert *cert, int valid, const char *host, void *payl ...@@ -968,6 +968,19 @@ static int proxy_cert_cb(git_cert *cert, int valid, const char *host, void *payl
return valid ? 0 : GIT_ECERTIFICATE; return valid ? 0 : GIT_ECERTIFICATE;
} }
void test_online_clone__proxy_invalid_url(void)
{
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
g_options.fetch_opts.proxy_opts.credentials = proxy_cred_cb;
g_options.fetch_opts.proxy_opts.certificate_check = proxy_cert_cb;
g_options.fetch_opts.proxy_opts.url = "noschemeorport";
cl_git_fail_with(GIT_EINVALIDSPEC, git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
g_options.fetch_opts.proxy_opts.url = "noscheme:8080";
cl_git_fail_with(GIT_EINVALIDSPEC, git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
}
void test_online_clone__proxy_credentials_request(void) void test_online_clone__proxy_credentials_request(void)
{ {
git_str url = GIT_STR_INIT; git_str url = GIT_STR_INIT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment