mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
ID: 3600911 - 'lib/ipmi_fru.c' - rewrite of ipmi_fru_get_multirec_from_file()
Commit is a rewrite of function ipmi_fru_get_multirec_from_file() in 'lib/ipmi_fru.c'. Changes: * argument size is checked; size must be greater than 0 * argument pFileName is checked * return value of seek() is checked * error messages are printed on STDERR * code flow got a re-work
This commit is contained in:
parent
39ad0d62cc
commit
e99e525a53
@ -42,6 +42,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
#if HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
@ -3850,28 +3851,40 @@ ipmi_fru_get_adjust_size_from_buffer(uint8_t * fru_data, uint32_t *pSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ipmi_fru_get_multirec_from_file(char * pFileName,
|
ipmi_fru_get_multirec_from_file(char * pFileName, uint8_t * pBufArea,
|
||||||
uint8_t * pBufArea,
|
uint32_t size, uint32_t offset)
|
||||||
uint32_t size,
|
|
||||||
uint32_t offset)
|
|
||||||
{
|
{
|
||||||
FILE * pFile;
|
FILE * pFile;
|
||||||
uint32_t len = 0;
|
uint32_t len = 0;
|
||||||
|
if (size < 0) {
|
||||||
pFile = fopen(pFileName,"rb");
|
return (-1);
|
||||||
if (pFile) {
|
|
||||||
fseek(pFile, offset,SEEK_SET);
|
|
||||||
len = fread(pBufArea, size, 1, pFile);
|
|
||||||
fclose(pFile);
|
|
||||||
} else {
|
|
||||||
printf("Error opening file\n");
|
|
||||||
}
|
}
|
||||||
|
if (pFileName == NULL) {
|
||||||
|
lprintf(LOG_ERR, "Invalid file name given.");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
pFile = fopen(pFileName, "rb");
|
||||||
|
if (!pFile) {
|
||||||
|
lprintf(LOG_ERR, "Error opening file '%s': %i -> %s.", pFileName, errno,
|
||||||
|
strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
if (fseek(pFile, offset, SEEK_SET) != 0) {
|
||||||
|
lprintf(LOG_ERR, "Failed to seek in file '%s': %i -> %s.", pFileName, errno,
|
||||||
|
strerror(errno));
|
||||||
|
fclose(pFile);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
len = fread(pBufArea, size, 1, pFile);
|
||||||
|
fclose(pFile);
|
||||||
|
|
||||||
if (len != 1) {
|
if (len != 1) {
|
||||||
printf("Error with file %s\n", pFileName);
|
lprintf(LOG_ERR, "Error in file '%s'.", pFileName);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user