Skip to content

Commit

Permalink
Merge pull request #1376 from siemens/fix/pfile/warnings
Browse files Browse the repository at this point in the history
fix(pfile): Fix warnings in ununpack and wget
Reviewed-by: shaheem.azmal@siemens.com, anupam.ghosh@siemens.com
Tested-by: shaheem.azmal@siemens.com
  • Loading branch information
shaheemazmalmmd committed Jun 21, 2019
2 parents ccd4340 + 9705b2d commit 02af914
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
17 changes: 8 additions & 9 deletions src/ununpack/agent/utils.c
Expand Up @@ -18,10 +18,6 @@
* \file
* \brief Contains all utility functions used by FOSSology
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ununpack.h"
#include "externs.h"
#include "regex.h"
Expand Down Expand Up @@ -1569,18 +1565,22 @@ int DisplayContainerInfo (ContainerInfo *CI, int Cmd)
{
CksumFile *CF;
Cksum *Sum;
char SHA256[64], command[1000] = "sha256sum ";
strcat(command,CI->Source);
char SHA256[65];
char command[PATH_MAX + 13];
int retcode = -1;
int read = 0;

memset(SHA256, '\0', sizeof(SHA256));

CF = SumOpenFile(CI->Source);
snprintf(command, PATH_MAX + 13, "sha256sum '%s'", CI->Source);
FILE* file = popen(command, "r");
if (file != (FILE*) NULL)
{
fscanf(file, "%64s", SHA256);
read = fscanf(file, "%64s", SHA256);
retcode = WEXITSTATUS(pclose(file));
}
if (file == (FILE*) NULL || retcode != 0)
if (file == (FILE*) NULL || retcode != 0 || read != 1)
{
LOG_FATAL("Unable to calculate SHA256 of %s\n", CI->Source);
SafeExit(56);
Expand Down Expand Up @@ -1767,7 +1767,6 @@ void Usage (char *Name, char *Version)
CheckCommands(Quiet);
} /* Usage() */


/**
* @brief Dummy postgresql notice processor.
* This prevents Notices from being written to stderr.
Expand Down
19 changes: 11 additions & 8 deletions src/wget_agent/agent/wget_agent.c
Expand Up @@ -94,16 +94,19 @@ void DBLoadGold()
char SQL[MAXCMD];
long PfileKey;
char *Path;
char SHA256[64], command[1000] = "sha256sum ";
char SHA256[65], command[PATH_MAX + 13];
FILE *Fin;
int rc;
int rc = -1;
PGresult *result;
int retcode = -1;
int read = 0;

memset(SHA256, '\0', sizeof(SHA256));

LOG_VERBOSE0("Processing %s",GlobalTempFile);
Fin = fopen(GlobalTempFile,"rb");

// Calculate sha256 value
strcat(command,GlobalTempFile);
snprintf(command, PATH_MAX + 13, "sha256sum '%s'", GlobalTempFile);
FILE* file = popen(command, "r");

if (!Fin)
Expand All @@ -114,13 +117,13 @@ void DBLoadGold()
}
if (file != (FILE*) NULL)
{
fscanf(file, "%64s", SHA256);
retcode = WEXITSTATUS(pclose(file));
read = fscanf(file, "%64s", SHA256);
rc = WEXITSTATUS(pclose(file));
}
if (file == (FILE*) NULL || retcode != 0)
if (file == (FILE*) NULL || rc != 0 || read != 1)
{
LOG_FATAL("Unable to calculate SHA256 of %s\n", GlobalTempFile);
SafeExit(2);
SafeExit(56);
}
Sum = SumComputeFile(Fin);
fclose(Fin);
Expand Down

0 comments on commit 02af914

Please sign in to comment.