Commit a79cc76f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: fix proxy URL parsing, improve coverage

parent 8a9a8d9f
...@@ -125,11 +125,11 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds, ...@@ -125,11 +125,11 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
vlc_tls_t *session = NULL; vlc_tls_t *session = NULL;
bool ptwo = false; bool ptwo = false;
#if TLS_OVER_TLS #if TLS_OVER_TLS
if (strcasecmp(url.psz_protocol, "https")) if (!strcasecmp(url.psz_protocol, "https"))
session = vlc_https_connect(creds, url.psz_host, url.i_port, &ptwo); session = vlc_https_connect(creds, url.psz_host, url.i_port, &ptwo);
else else
#endif #endif
if (strcasecmp(url.psz_protocol, "http")) if (!strcasecmp(url.psz_protocol, "http"))
session = vlc_http_connect(creds ? creds->p_parent : NULL, session = vlc_http_connect(creds ? creds->p_parent : NULL,
url.psz_host, url.i_port); url.psz_host, url.i_port);
else else
......
...@@ -99,11 +99,11 @@ static void *proxy_thread(void *data) ...@@ -99,11 +99,11 @@ static void *proxy_thread(void *data)
vlc_assert_unreachable(); vlc_assert_unreachable();
} }
int main(void) static int server_socket(unsigned *port)
{ {
int lfd = socket(PF_INET6, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP); int fd = socket(PF_INET6, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP);
if (lfd == -1) if (fd == -1)
return 77; return -1;
struct sockaddr_in6 addr = { struct sockaddr_in6 addr = {
.sin6_family = AF_INET6, .sin6_family = AF_INET6,
...@@ -114,27 +114,53 @@ int main(void) ...@@ -114,27 +114,53 @@ int main(void)
}; };
socklen_t addrlen = sizeof (addr); socklen_t addrlen = sizeof (addr);
if (bind(lfd, (struct sockaddr *)&addr, addrlen) if (bind(fd, (struct sockaddr *)&addr, addrlen)
|| listen(lfd, 255)) || getsockname(fd, &addr, &addrlen))
{ {
close(lfd); close(fd);
return 77; return -1;
} }
*port = ntohs(addr.sin6_port);
return fd;
}
int main(void)
{
char *url; char *url;
unsigned port;
bool two; bool two;
getsockname(lfd, &addr, &addrlen); /* Test bad URLs */
if (asprintf(&url, "https://[::1]:%u", ntohs(addr.sin6_port)) < 0) vlc_https_connect_proxy(NULL, "www.example.com", 0, &two,
"/test");
vlc_https_connect_proxy(NULL, "www.example.com", 0, &two,
"ftp://proxy.example.com/");
int lfd = server_socket(&port);
if (lfd == -1)
return 77;
if (asprintf(&url, "http://[::1]:%u", port) < 0)
url = NULL; url = NULL;
assert(url != NULL); assert(url != NULL);
vlc_thread_t th; /* Test connection failure */
vlc_https_connect_proxy(NULL, "www.example.com", 0, &two, url);
if (listen(lfd, 255))
{
close(lfd);
return 77;
}
vlc_thread_t th;
if (vlc_clone(&th, proxy_thread, (void*)(intptr_t)lfd, if (vlc_clone(&th, proxy_thread, (void*)(intptr_t)lfd,
VLC_THREAD_PRIORITY_LOW)) VLC_THREAD_PRIORITY_LOW))
assert(!"Thread error"); assert(!"Thread error");
/* Test proxy error */
vlc_https_connect_proxy(NULL, "www.example.com", 0, &two, url); vlc_https_connect_proxy(NULL, "www.example.com", 0, &two, url);
vlc_cancel(th); vlc_cancel(th);
......
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