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