]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Simplify openconnect_set_http_proxy() and report errors
authorDavid Woodhouse <dwmw2@infradead.org>
Fri, 2 Aug 2019 21:52:22 +0000 (14:52 -0700)
committerDavid Woodhouse <dwmw2@infradead.org>
Fri, 2 Aug 2019 21:52:22 +0000 (14:52 -0700)
There was a failure mode where openconnect would exit silently if given
a --proxy= argument it didn't like. Make it print errors in all cases,
and eliminate an -ENOMEM case which seems entirely gratuitous; I don't
think internal_parse_url() needs the 'const char *url' it's passed to
be hackishly writeable, so there is no need to allocate our own copy.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
http.c

diff --git a/http.c b/http.c
index bd531abce0f9672740e04e6e28ee553d09a6a255..bca744816a771f650d9fbdb94036fe1964816ecb 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1369,21 +1369,20 @@ int process_proxy(struct openconnect_info *vpninfo, int ssl_sock)
 int openconnect_set_http_proxy(struct openconnect_info *vpninfo,
                               const char *proxy)
 {
-       char *url = strdup(proxy), *p;
+       char *p;
        int ret;
 
-       if (!url)
-               return -ENOMEM;
-
        free(vpninfo->proxy_type);
        vpninfo->proxy_type = NULL;
        free(vpninfo->proxy);
        vpninfo->proxy = NULL;
 
-       ret = internal_parse_url(url, &vpninfo->proxy_type, &vpninfo->proxy,
+       ret = internal_parse_url(proxy, &vpninfo->proxy_type, &vpninfo->proxy,
                                 &vpninfo->proxy_port, NULL, 80);
-       if (ret)
-               goto out;
+       if (ret) {
+               vpn_progress(vpninfo, PRG_ERR, _("Failed to parse proxy '%s'\n"), proxy);
+               return ret;
+       }
 
        p = strrchr(vpninfo->proxy, '@');
        if (p) {
@@ -1412,9 +1411,8 @@ int openconnect_set_http_proxy(struct openconnect_info *vpninfo,
                vpninfo->proxy = NULL;
                return -EINVAL;
        }
- out:
-       free(url);
-       return ret;
+
+       return 0;
 }
 
 void http_common_headers(struct openconnect_info *vpninfo, struct oc_text_buf *buf)