mirror of
https://github.com/curl/curl.git
synced 2025-09-07 21:05:09 +03:00
netrc: deal with null token better
If there is no length of the token, assign a blank string to avoid risking it being NULL. Pointed out by Coverity Closes #17351
This commit is contained in:
parent
473b3e51d6
commit
f5b7eb27f0
11
lib/netrc.c
11
lib/netrc.c
|
@ -220,7 +220,12 @@ static NETRCcode parsenetrc(struct store_netrc *store,
|
|||
}
|
||||
}
|
||||
|
||||
tok = curlx_dyn_ptr(&token);
|
||||
if(curlx_dyn_len(&token))
|
||||
tok = curlx_dyn_ptr(&token);
|
||||
else
|
||||
/* since tok might actually be NULL for no content, set it to blank
|
||||
to avoid having to deal with it being NULL */
|
||||
tok = "";
|
||||
|
||||
switch(state) {
|
||||
case NOTHING:
|
||||
|
@ -247,7 +252,7 @@ static NETRCcode parsenetrc(struct store_netrc *store,
|
|||
}
|
||||
break;
|
||||
case MACDEF:
|
||||
if(!tok || !*tok)
|
||||
if(!*tok)
|
||||
state = NOTHING;
|
||||
break;
|
||||
case HOSTFOUND:
|
||||
|
@ -268,7 +273,7 @@ static NETRCcode parsenetrc(struct store_netrc *store,
|
|||
else {
|
||||
our_login = TRUE;
|
||||
free(login);
|
||||
login = strdup(tok ? tok : "");
|
||||
login = strdup(tok);
|
||||
if(!login) {
|
||||
retcode = NETRC_OUT_OF_MEMORY; /* allocation failed */
|
||||
goto out;
|
||||
|
|
Loading…
Reference in New Issue
Block a user