Further fixes based on coverty scan report

Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
This commit is contained in:
Shreenidhi Shedi 2020-12-03 20:53:22 +05:30
parent a2ceabe13b
commit 6f7d3cce32
5 changed files with 21 additions and 3 deletions

View File

@ -197,12 +197,12 @@ TDNFInitCmdLineRepo(
BAIL_ON_TDNF_ERROR(dwError);
pRepo = repo_create(pPool, "@cmdline");
if (!pRepo)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
pSolvRepoInfo->pRepo = pRepo;
pRepo->appdata = pSolvRepoInfo;
@ -214,6 +214,11 @@ cleanup:
TDNF_SAFE_FREE_MEMORY(pSolvRepoInfo);
return dwError;
error:
/*
* coverty scan throws below warning
* Execution cannot reach this statement: "repo_free(pRepo, 1);"
* Ignoring this because it's good to have this condition check
*/
if(pRepo)
{
repo_free(pRepo, 1);

View File

@ -458,7 +458,14 @@ cleanup:
}
if (!IsNullOrEmptyString(pszRpmCacheDir))
{
rmdir(pszRpmCacheDir);
if (rmdir(pszRpmCacheDir))
{
/*
* Not using BAIL_ON_TDNF_SYSTEM_ERROR here to prevent infinite loop
* Also it makes easy to read the code
*/
dwError = ERROR_TDNF_SYSTEM_BASE + errno;
}
}
TDNF_SAFE_FREE_MEMORY(pszFilePath);
TDNF_SAFE_FREE_MEMORY(pszRpmCacheDir);

View File

@ -9,6 +9,8 @@
#include <sys/stat.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
// libsolv
#include <solv/evr.h>

View File

@ -508,6 +508,7 @@ SolvCreateMetaDataCache(
char *pszSolvCacheDir = NULL;
char *pszTempSolvFile = NULL;
char *pszCacheFilePath = NULL;
mode_t mask = 0;
if (!pSack || !pSolvRepoInfo|| !pSolvRepoInfo->nCookieSet)
{
@ -539,7 +540,10 @@ SolvCreateMetaDataCache(
}
BAIL_ON_TDNF_LIBSOLV_ERROR(dwError);
}
pszTempSolvFile = solv_dupjoin(pszSolvCacheDir, "/", ".newsolv-XXXXXX");
mask = umask(S_IRUSR | S_IWUSR | S_IRWXG);
umask(mask);
fd = mkstemp(pszTempSolvFile);
if (fd < 0)
{

View File

@ -222,7 +222,7 @@ static bool IsTdnfAlreadyRunning(void)
{
bool ret = false;
glockfd = open(TDNF_INSTANCE_LOCK_FILE, O_CREAT);
glockfd = open(TDNF_INSTANCE_LOCK_FILE, O_CREAT | O_RDONLY);
if (glockfd < 0)
{
fprintf(stderr, "ERROR: failed to create instance lock file\n");