mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-01-21 16:42:19 +08:00
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:
parent
ee6c9be382
commit
393ae97425
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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>
|
||||
@ -503,43 +504,45 @@ static tKFWUM_Status KfwumGetFileSize(unsigned char * pFileName,
|
||||
*/
|
||||
#define MAX_BUFFER_SIZE 1024*16
|
||||
static tKFWUM_Status KfwumSetupBuffersFromFile(unsigned char * pFileName,
|
||||
unsigned long fileSize)
|
||||
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");
|
||||
pFileHandle = fopen((const char *)pFileName, "rb");
|
||||
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;
|
||||
|
||||
if(pFileHandle)
|
||||
{
|
||||
int count = fileSize / MAX_BUFFER_SIZE;
|
||||
int modulus = fileSize % MAX_BUFFER_SIZE;
|
||||
int qty =0;
|
||||
|
||||
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)
|
||||
{
|
||||
status = KFWUM_STATUS_OK;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
return(status);
|
||||
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) {
|
||||
status = KFWUM_STATUS_OK;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
fclose(pFileHandle);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* KfwumShowProgress - helper routine to display progress bar
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user