[vlc-commits] https: fix proxy URL parsing, improve coverage

Rémi Denis-Courmont git at videolan.org
Thu Jan 7 18:56:37 CET 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jan  7 19:56:16 2016 +0200| [a79cc76fd946924bee92ea0fd17b67ca43b582a9] | committer: Rémi Denis-Courmont

https: fix proxy URL parsing, improve coverage

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a79cc76fd946924bee92ea0fd17b67ca43b582a9
---

 modules/access/http/tunnel.c      |    4 ++--
 modules/access/http/tunnel_test.c |   48 ++++++++++++++++++++++++++++---------
 2 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/modules/access/http/tunnel.c b/modules/access/http/tunnel.c
index b26efbd..4b931e1 100644
--- a/modules/access/http/tunnel.c
+++ b/modules/access/http/tunnel.c
@@ -125,11 +125,11 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
     vlc_tls_t *session = NULL;
     bool ptwo = false;
 #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);
     else
 #endif
-    if (strcasecmp(url.psz_protocol, "http"))
+    if (!strcasecmp(url.psz_protocol, "http"))
         session = vlc_http_connect(creds ? creds->p_parent : NULL,
                                    url.psz_host, url.i_port);
     else
diff --git a/modules/access/http/tunnel_test.c b/modules/access/http/tunnel_test.c
index d4fe87e..95f7d79 100644
--- a/modules/access/http/tunnel_test.c
+++ b/modules/access/http/tunnel_test.c
@@ -99,11 +99,11 @@ static void *proxy_thread(void *data)
     vlc_assert_unreachable();
 }
 
-int main(void)
+static int server_socket(unsigned *port)
 {
-    int lfd = socket(PF_INET6, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP);
-    if (lfd == -1)
-        return 77;
+    int fd = socket(PF_INET6, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP);
+    if (fd == -1)
+        return -1;
 
     struct sockaddr_in6 addr = {
         .sin6_family = AF_INET6,
@@ -114,27 +114,53 @@ int main(void)
     };
     socklen_t addrlen = sizeof (addr);
 
-    if (bind(lfd, (struct sockaddr *)&addr, addrlen)
-     || listen(lfd, 255))
+    if (bind(fd, (struct sockaddr *)&addr, addrlen)
+     || getsockname(fd, &addr, &addrlen))
     {
-        close(lfd);
-        return 77;
+        close(fd);
+        return -1;
     }
 
+    *port = ntohs(addr.sin6_port);
+    return fd;
+}
+
+int main(void)
+{
     char *url;
+    unsigned port;
     bool two;
 
-    getsockname(lfd, &addr, &addrlen);
-    if (asprintf(&url, "https://[::1]:%u", ntohs(addr.sin6_port)) < 0)
+    /* Test bad URLs */
+    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;
+
     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,
                   VLC_THREAD_PRIORITY_LOW))
         assert(!"Thread error");
 
+    /* Test proxy error */
     vlc_https_connect_proxy(NULL, "www.example.com", 0, &two, url);
 
     vlc_cancel(th);



More information about the vlc-commits mailing list