Follow-up to f9c7ba9096

Coverity CID 1453474

Closes #4291
This commit is contained in:
Daniel Stenberg 2019-09-03 13:46:36 +02:00
Родитель 4ac2884003
Коммит 158dcb9f86
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5CC908FDB71E12C2
1 изменённых файлов: 12 добавлений и 7 удалений

Просмотреть файл

@ -218,8 +218,10 @@ int Curl_parsenetrc(const char *host,
char *filealloc = NULL; char *filealloc = NULL;
if(!netrcfile) { if(!netrcfile) {
char *home = curl_getenv("HOME"); /* portable environment reader */ char *home = NULL;
if(home) { char *homea = curl_getenv("HOME"); /* portable environment reader */
if(homea) {
home = homea;
#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID) #if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
} }
else { else {
@ -227,9 +229,7 @@ int Curl_parsenetrc(const char *host,
char pwbuf[1024]; char pwbuf[1024];
if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res) if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res)
&& pw_res) { && pw_res) {
home = strdup(pw.pw_dir); home = pw.pw_dir;
if(!home)
return -1;
} }
#elif defined(HAVE_GETPWUID) && defined(HAVE_GETEUID) #elif defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
} }
@ -247,8 +247,10 @@ int Curl_parsenetrc(const char *host,
memory) */ memory) */
filealloc = curl_maprintf("%s%s.netrc", home, DIR_CHAR); filealloc = curl_maprintf("%s%s.netrc", home, DIR_CHAR);
if(!filealloc) if(!filealloc) {
free(homea);
return -1; return -1;
}
retcode = parsenetrc(host, loginp, passwordp, login_changed, retcode = parsenetrc(host, loginp, passwordp, login_changed,
password_changed, filealloc); password_changed, filealloc);
free(filealloc); free(filealloc);
@ -256,13 +258,16 @@ int Curl_parsenetrc(const char *host,
if(retcode == NETRC_FILE_MISSING) { if(retcode == NETRC_FILE_MISSING) {
/* fallback to the old-style "_netrc" file */ /* fallback to the old-style "_netrc" file */
filealloc = curl_maprintf("%s%s_netrc", home, DIR_CHAR); filealloc = curl_maprintf("%s%s_netrc", home, DIR_CHAR);
if(!filealloc) if(!filealloc) {
free(homea);
return -1; return -1;
}
retcode = parsenetrc(host, loginp, passwordp, login_changed, retcode = parsenetrc(host, loginp, passwordp, login_changed,
password_changed, filealloc); password_changed, filealloc);
free(filealloc); free(filealloc);
} }
#endif #endif
free(homea);
} }
else else
retcode = parsenetrc(host, loginp, passwordp, login_changed, retcode = parsenetrc(host, loginp, passwordp, login_changed,