mirror of
https://github.com/curl/curl.git
synced 2026-08-26 00:33:34 +03:00
urlapi: fix memleaks on error in parse_hostname_login()
Detected by GitHub Code Quality Follow-up toacd82c8bfd#11006 Follow-up to4183b8fe9a#8049 Closes #21879
This commit is contained in:
parent
9c1ebea359
commit
7c34365cce
2 changed files with 75 additions and 10 deletions
26
lib/urlapi.c
26
lib/urlapi.c
|
|
@ -253,12 +253,18 @@ CURLUcode Curl_junkscan(const char *url, size_t *urllen, bool allowspace)
|
|||
* Parse the login details (username, password and options) from the URL and
|
||||
* strip them out of the hostname
|
||||
*
|
||||
* @unittest 1675
|
||||
*/
|
||||
static CURLUcode parse_hostname_login(struct Curl_URL *u,
|
||||
const char *login,
|
||||
size_t len,
|
||||
unsigned int flags,
|
||||
size_t *offset) /* to the hostname */
|
||||
UNITTEST CURLUcode parse_hostname_login(struct Curl_URL *u,
|
||||
const char *login,
|
||||
size_t len,
|
||||
unsigned int flags,
|
||||
size_t *hostname_offset);
|
||||
UNITTEST CURLUcode parse_hostname_login(struct Curl_URL *u,
|
||||
const char *login,
|
||||
size_t len,
|
||||
unsigned int flags,
|
||||
size_t *hostname_offset)
|
||||
{
|
||||
CURLUcode ures = CURLUE_OK;
|
||||
CURLcode result;
|
||||
|
|
@ -278,7 +284,7 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u,
|
|||
|
||||
DEBUGASSERT(login);
|
||||
|
||||
*offset = 0;
|
||||
*hostname_offset = 0;
|
||||
ptr = memchr(login, '@', len);
|
||||
if(!ptr)
|
||||
goto out;
|
||||
|
|
@ -326,7 +332,7 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u,
|
|||
}
|
||||
|
||||
/* the hostname starts at this offset */
|
||||
*offset = ptr - login;
|
||||
*hostname_offset = ptr - login;
|
||||
return CURLUE_OK;
|
||||
|
||||
out:
|
||||
|
|
@ -334,9 +340,9 @@ out:
|
|||
curlx_free(userp);
|
||||
curlx_free(passwdp);
|
||||
curlx_free(optionsp);
|
||||
u->user = NULL;
|
||||
u->password = NULL;
|
||||
u->options = NULL;
|
||||
curlx_safefree(u->user);
|
||||
curlx_safefree(u->password);
|
||||
curlx_safefree(u->options);
|
||||
|
||||
return ures;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue