mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-01-21 08:34:29 +08:00
ID:230 - check return value of malloc() in lib/ipmi_ekanalyzer.c
Return value of malloc() must be checked. Commit mends this.
This commit is contained in:
parent
9341982a38
commit
8bd9659101
@ -602,10 +602,13 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
|
||||
*/
|
||||
filename_size = strlen(argv[index]) - SIZE_OF_FILE_TYPE + 1;
|
||||
if (filename_size > 0) {
|
||||
/* TODO - check malloc() retval */
|
||||
filename[i] = malloc( filename_size );
|
||||
if (filename[i] != NULL) {
|
||||
strcpy(filename[i], &argv[index][SIZE_OF_FILE_TYPE]);
|
||||
} else {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
rc = ERROR_STATUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rc = OK_STATUS;
|
||||
@ -2205,6 +2208,9 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record,
|
||||
int index_oem = 0;
|
||||
amc_record->oem_guid = malloc(amc_record->guid_count * \
|
||||
sizeof(struct fru_picmgext_guid));
|
||||
if (amc_record->oem_guid == NULL) {
|
||||
return ERROR_STATUS;
|
||||
}
|
||||
for (index_oem = 0; index_oem < amc_record->guid_count;
|
||||
index_oem++) {
|
||||
memcpy(&amc_record->oem_guid[index_oem].guid,
|
||||
@ -2232,6 +2238,9 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record,
|
||||
int ch_index = 0;
|
||||
amc_record->ch_desc = malloc((amc_record->ch_count) * \
|
||||
sizeof(struct fru_picmgext_amc_channel_desc_record));
|
||||
if (amc_record->ch_desc == NULL) {
|
||||
return ERROR_STATUS;
|
||||
}
|
||||
for (ch_index = 0; ch_index < amc_record->ch_count;
|
||||
ch_index++) {
|
||||
unsigned int data;
|
||||
@ -2255,6 +2264,9 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record,
|
||||
int i=0;
|
||||
amc_record->link_desc = malloc(amc_record->link_desc_count * \
|
||||
sizeof(struct fru_picmgext_amc_link_desc_record));
|
||||
if (amc_record->link_desc == NULL) {
|
||||
return ERROR_STATUS;
|
||||
}
|
||||
for (i = 0; i< amc_record->link_desc_count; i++) {
|
||||
unsigned int data[2];
|
||||
struct fru_picmgext_amc_link_desc_record *src, *dst;
|
||||
@ -2767,7 +2779,6 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type,
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return (size_t)(-1);
|
||||
}
|
||||
|
||||
ret = fread(additional_data, size_board, 1, input_file);
|
||||
if ((ret != 1) || ferror(input_file)) {
|
||||
lprintf(LOG_ERR, "Invalid Additional Data!");
|
||||
@ -4046,14 +4057,18 @@ ipmi_ekanalyzer_fru_file2structure(char *filename,
|
||||
|
||||
fseek(input_file, multi_offset, SEEK_SET);
|
||||
while (!feof(input_file)) {
|
||||
/* TODO - check malloc() */
|
||||
*list_record = malloc(sizeof(struct ipmi_ek_multi_header));
|
||||
if (*list_record == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return ERROR_STATUS;
|
||||
}
|
||||
ret = fread(&(*list_record)->header, START_DATA_OFFSET, 1,
|
||||
input_file);
|
||||
if ((ret != 1) || ferror(input_file)) {
|
||||
/* TODO - no free?! */
|
||||
lprintf(LOG_ERR, "Invalid Header!");
|
||||
free(*list_record);
|
||||
*list_record = NULL;
|
||||
fclose(input_file);
|
||||
lprintf(LOG_ERR, "Invalid Header!");
|
||||
return ERROR_STATUS;
|
||||
}
|
||||
if ((*list_record)->header.len == 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user