ID: 3608765 - Fixed bug in ipmi_ek_display_board_info_area()

Previous versions were not setting the file_offset properly if a Custom
board type was found, which would prevent subsequent dissectors from
operating properly and terminating the output of 'ipmitool ekanalyze
frushow oc=<atca carrier fruinfo>' early.

Rewrote ipmi_ek_display_board_info_area() to fix indentation and
to properly set the file_offset and end the while loop if a Custom
board_type was found.

Previous versions were also abusing the board_length variable,
treating it as an int and using it to break out of the loop.

Commit for Dan Gora
This commit is contained in:
Zdenek Styblik 2013-04-18 07:57:26 +00:00
parent 4299cfa385
commit de4de4fc96

View File

@ -42,6 +42,9 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#define NO_MORE_INFO_FIELD 0xc1
#define TYPE_CODE 0xc0 /*Language code*/
/***************************************************************** /*****************************************************************
* CONSTANT * CONSTANT
*****************************************************************/ *****************************************************************/
@ -2622,54 +2625,64 @@ static size_t
ipmi_ek_display_board_info_area(FILE * input_file, char * board_type, ipmi_ek_display_board_info_area(FILE * input_file, char * board_type,
unsigned int * board_length) unsigned int * board_length)
{ {
size_t file_offset = ftell (input_file); size_t file_offset;
unsigned char len = 0; unsigned char len = 0;
unsigned int size_board = 0;
if (input_file == NULL || board_type == NULL
|| board_length == NULL) {
return (size_t)(-1);
}
file_offset = ftell(input_file);
/* Board length */ /* Board length */
if (!feof(input_file)) { if (!feof(input_file)) {
fread(&len, 1, 1, input_file); fread(&len, 1, 1, input_file);
(*board_length)--; (*board_length)--;
} }
/* Board Data */ /* Board Data */
if ( !feof(input_file) ){ if (feof(input_file)) {
unsigned int size_board = 0; printf("No Board Data found!\n");
goto out;
}
/* Bit 5:0 of Board Mfg type represent legnth */ /* Bit 5:0 of Board Mfg type represent legnth */
size_board = (len & 0x3f); size_board = (len & 0x3f);
if (size_board > 0){ if (size_board == 0) {
if ( strncmp( board_type, "Custom", 6 ) == 0 ){ printf("%s: None\n", board_type);
#define NO_MORE_INFO_FIELD 0xc1 goto out;
while ( !feof(input_file) && (board_length > 0) ){ }
if (len != NO_MORE_INFO_FIELD){ if (strncmp(board_type, "Custom", 6 ) != 0) {
printf("Additional Custom Mfg. length: 0x%02x\n", len); unsigned char *data;
if ( (size_board > 0) && (size_board < (*board_length)) ){ unsigned int i = 0;
unsigned char * additional_data = NULL; data = malloc(size_board);
int i=0; if (data == NULL) {
additional_data = malloc (size_board); lprintf(LOG_ERR, "ipmitool: malloc failure");
if (additional_data != NULL){ return (size_t)(-1);
fread ( additional_data, size_board, 1, input_file ); }
printf("Additional Custom Mfg. Data: %02x", fread(data, size_board, 1, input_file);
additional_data[0]); printf("%s type: 0x%02x\n", board_type, len);
for ( i =1; i<size_board; i++){ printf("%s: ", board_type);
printf("-%02x", additional_data[i]); for (i = 0; i < size_board; i++) {
if ((len & TYPE_CODE) == TYPE_CODE) {
printf("%c", data[i]);
} else {
/* other than language code (binary, BCD,
* ASCII 6 bit...) is not supported
*/
printf("%02x", data[i]);
}
} }
printf("\n"); printf("\n");
free(additional_data); free(data);
additional_data = NULL;
(*board_length) -= size_board; (*board_length) -= size_board;
goto out;
} }
} while (!feof(input_file)) {
else{ if (len == NO_MORE_INFO_FIELD) {
printf("No Additional Custom Mfg. %d\n", *board_length);
board_length = 0;
}
}
else{
unsigned char padding; unsigned char padding;
/*take the rest of data in the area minus 1 byte of checksum*/ /* take the rest of data in the area minus 1 byte of
* checksum
*/
printf("Additional Custom Mfg. length: 0x%02x\n", len); printf("Additional Custom Mfg. length: 0x%02x\n", len);
padding = (*board_length) - 1; padding = (*board_length) - 1;
/*we reach the end of the record, so its length is set to 0*/
board_length = 0;
if ((padding > 0) && (!feof(input_file))) { if ((padding > 0) && (!feof(input_file))) {
printf("Unused space: %d (bytes)\n", padding); printf("Unused space: %d (bytes)\n", padding);
fseek(input_file, padding, SEEK_CUR); fseek(input_file, padding, SEEK_CUR);
@ -2678,43 +2691,37 @@ ipmi_ek_display_board_info_area( FILE * input_file, char * board_type,
unsigned char checksum = 0; unsigned char checksum = 0;
fread(&checksum, 1, 1, input_file); fread(&checksum, 1, 1, input_file);
printf("Checksum: 0x%02x\n", checksum); printf("Checksum: 0x%02x\n", checksum);
} }
goto out;
} }
} printf("Additional Custom Mfg. length: 0x%02x\n", len);
} if ((size_board > 0) && (size_board < (*board_length))) {
else{ unsigned char * additional_data = NULL;
unsigned char * data;
unsigned int i = 0; unsigned int i = 0;
#define TYPE_CODE 0xc0 /*Language code*/ additional_data = malloc(size_board);
if (additional_data == NULL) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (size_t)(-1);
}
data = malloc (size_board); fread(additional_data, size_board, 1, input_file);
fread ( data, size_board, 1, input_file ); printf("Additional Custom Mfg. Data: %02x",
printf("%s type: 0x%02x\n", board_type, len); additional_data[0]);
printf("%s: ", board_type); for (i = 1; i < size_board; i++) {
for ( i = 0; i < size_board; i++ ){ printf("-%02x", additional_data[i]);
if ( (len & TYPE_CODE) == TYPE_CODE ){
printf("%c", data[i]);
}
/*other than language code (binary, BCD, ASCII 6 bit...) is not
* supported */
else{
printf("%02x", data[i]);
}
} }
printf("\n"); printf("\n");
free(data); free(additional_data);
data = NULL;
(*board_length) -= size_board; (*board_length) -= size_board;
file_offset = ftell (input_file);
}
} }
else { else {
printf("%s: None\n", board_type); printf("No Additional Custom Mfg. %d\n", *board_length);
file_offset = ftell (input_file); goto out;
} }
} }
out:
file_offset = ftell(input_file);
return file_offset; return file_offset;
} }