summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-02-17 11:53:32 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-02-17 12:16:42 +0100
commit9ad74ade2c57564a7f92bbbb251b82891c982398 (patch)
tree444670012934cf768dafc87757cdab756c183b4c
parent94719e7285bb3d63d67129e2529def8f1bf1c5a8 (diff)
downloadcurl-bagder/parse_proxy-memleak.tar.gz
parse_proxy: fix a memory leak in the OOM pathbagder/parse_proxy-memleak
Reported-by: Jay Satiro Bug: https://github.com/curl/curl/pull/6591#issuecomment-780396541
-rw-r--r--lib/url.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/url.c b/lib/url.c
index ae6c8e9c1..1fc04af60 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2403,13 +2403,18 @@ static CURLcode parse_proxy(struct Curl_easy *data,
proxyinfo->proxytype = proxytype;
/* Is there a username and password given in this proxy url? */
- curl_url_get(uhp, CURLUPART_USER, &proxyuser, CURLU_URLDECODE);
- curl_url_get(uhp, CURLUPART_PASSWORD, &proxypasswd, CURLU_URLDECODE);
+ uc = curl_url_get(uhp, CURLUPART_USER, &proxyuser, CURLU_URLDECODE);
+ if(uc && (uc != CURLUE_NO_USER))
+ goto error;
+ uc = curl_url_get(uhp, CURLUPART_PASSWORD, &proxypasswd, CURLU_URLDECODE);
+ if(uc && (uc != CURLUE_NO_PASSWORD))
+ goto error;
+
if(proxyuser || proxypasswd) {
Curl_safefree(proxyinfo->user);
proxyinfo->user = proxyuser;
- result = Curl_setstropt(&data->state.aptr.proxyuser,
- proxyuser);
+ result = Curl_setstropt(&data->state.aptr.proxyuser, proxyuser);
+ proxyuser = NULL;
if(result)
goto error;
Curl_safefree(proxyinfo->passwd);
@@ -2421,8 +2426,8 @@ static CURLcode parse_proxy(struct Curl_easy *data,
}
}
proxyinfo->passwd = proxypasswd;
- result = Curl_setstropt(&data->state.aptr.proxypasswd,
- proxypasswd);
+ result = Curl_setstropt(&data->state.aptr.proxypasswd, proxypasswd);
+ proxypasswd = NULL;
if(result)
goto error;
conn->bits.proxy_user_passwd = TRUE; /* enable it */
@@ -2470,6 +2475,8 @@ static CURLcode parse_proxy(struct Curl_easy *data,
proxyinfo->host.name = host;
error:
+ free(proxyuser);
+ free(proxypasswd);
free(scheme);
curl_url_cleanup(uhp);
return result;