ID: 266 - file descriptor leak in ipmi_fwum and ipmi_ekanalyzer

Commit fixes fd leaks in 'lib/ipmi_ekananlyzer.c' and 'lib/ipmi_fwum.c'.

Commit fixes file descriptor leaks in ipmi_ekanalyzer_fru_file2structure(),
source 'lib/ipmi_ekanalyzer.c', and in KfwumGetFileSize(),
source 'lib/ipmi_fwum.c'.

Reported-by: dcb
This commit is contained in:
Zdenek Styblik 2013-08-23 14:39:52 +00:00
parent ee6c9be382
commit 393ae97425
2 changed files with 41 additions and 34 deletions

View File

@ -4040,6 +4040,7 @@ ipmi_ekanalyzer_fru_file2structure(char * filename,
ret = fread(&data, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Offset!");
fclose(input_file);
return ERROR_STATUS;
}
if (data == 0) {
@ -4060,6 +4061,7 @@ ipmi_ekanalyzer_fru_file2structure(char * filename,
input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Header!");
fclose(input_file);
return ERROR_STATUS;
}
if ((*list_record)->header.len == 0) {
@ -4078,6 +4080,7 @@ ipmi_ekanalyzer_fru_file2structure(char * filename,
1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Record Data!");
fclose(input_file);
return ERROR_STATUS;
}
if (verbose > 0)
@ -4103,6 +4106,7 @@ ipmi_ekanalyzer_fru_file2structure(char * filename,
}
record_count++;
}
fclose(input_file);
return OK_STATUS;
}

View File

@ -39,6 +39,7 @@
#include <time.h>
#include <unistd.h>
#include <ipmitool/log.h>
#include <ipmitool/helper.h>
#include <ipmitool/ipmi.h>
#include <ipmitool/ipmi_fwum.h>
@ -505,41 +506,43 @@ static tKFWUM_Status KfwumGetFileSize(unsigned char * pFileName,
static tKFWUM_Status KfwumSetupBuffersFromFile(unsigned char * pFileName,
unsigned long fileSize)
{
tKFWUM_Status status = KFWUM_STATUS_OK;
FILE * pFileHandle;
tKFWUM_Status status = KFWUM_STATUS_ERROR;
FILE *pFileHandle = NULL;
int count;
int modulus;
int qty = 0;
pFileHandle = fopen((const char *)pFileName, "rb");
if(pFileHandle)
{
int count = fileSize / MAX_BUFFER_SIZE;
int modulus = fileSize % MAX_BUFFER_SIZE;
int qty =0;
if (pFileHandle == NULL) {
lprintf(LOG_ERR, "Failed to open '%s' for reading.",
(char *)pFileName);
return KFWUM_STATUS_ERROR;
}
count = fileSize / MAX_BUFFER_SIZE;
modulus = fileSize % MAX_BUFFER_SIZE;
rewind(pFileHandle);
for(qty=0;qty<count;qty++)
{
KfwumShowProgress((const unsigned char *)"Reading Firmware from File", qty, count );
if(fread(&firmBuf[qty*MAX_BUFFER_SIZE], 1, MAX_BUFFER_SIZE ,pFileHandle)
== MAX_BUFFER_SIZE)
{
for (qty=0; qty < count; qty++) {
KfwumShowProgress((const unsigned char *)"Reading Firmware from File",
qty, count);
if (fread(&firmBuf[qty * MAX_BUFFER_SIZE], 1,
MAX_BUFFER_SIZE,
pFileHandle) == MAX_BUFFER_SIZE) {
status = KFWUM_STATUS_OK;
}
}
if( modulus )
{
if(fread(&firmBuf[qty*MAX_BUFFER_SIZE], 1, modulus, pFileHandle) == modulus)
{
if (modulus) {
if (fread(&firmBuf[qty * MAX_BUFFER_SIZE], 1,
modulus, pFileHandle) == modulus) {
status = KFWUM_STATUS_OK;
}
}
if(status == KFWUM_STATUS_OK)
{
KfwumShowProgress((const unsigned char *)"Reading Firmware from File", 100, 100);
if (status == KFWUM_STATUS_OK) {
KfwumShowProgress((const unsigned char *)"Reading Firmware from File",
100, 100);
}
}
return(status);
fclose(pFileHandle);
return status;
}
/* KfwumShowProgress - helper routine to display progress bar