From: David Woodhouse Date: Fri, 2 Aug 2019 21:52:22 +0000 (-0700) Subject: Simplify openconnect_set_http_proxy() and report errors X-Git-Tag: v8.04~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=51676600b366d165d0ce1c9cd34d53bce91bc731;p=users%2Fdwmw2%2Fopenconnect.git Simplify openconnect_set_http_proxy() and report errors 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 --- diff --git a/http.c b/http.c index bd531abc..bca74481 100644 --- 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)