On Fri, Mar 22, 2013 at 1:17 AM, Dan Gora <d...@adax.com> wrote: > 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. > > Signed-off-by: Dan Gora <d...@adax.com> > ---
Attached is a patch which addresses couple issues: * malloc() is being checked * returned size on error is (-1) * possible segfault if one of parameters is NULL Regards, Z. > ipmitool/lib/ipmi_ekanalyzer.c | 180 ++++++++++++++++++++------------------- > 1 files changed, 92 insertions(+), 88 deletions(-) > > diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c > index b1c5cb2..2fcf4e5 100644 > --- a/ipmitool/lib/ipmi_ekanalyzer.c > +++ b/ipmitool/lib/ipmi_ekanalyzer.c > @@ -2611,98 +2611,102 @@ static size_t > ipmi_ek_display_board_info_area( FILE * input_file, char * board_type, > unsigned int * board_length ) > { > - size_t file_offset = ftell (input_file); > - unsigned char len = 0; > - /* Board length*/ > - if ( !feof(input_file) ){ > - fread ( &len, 1, 1, input_file ); > - (*board_length)--; > - } > - /* Board Data */ > - if ( !feof(input_file) ){ > - unsigned int size_board = 0; > + size_t file_offset = ftell (input_file); > + unsigned char len = 0; > + unsigned int size_board = 0; > > - /*Bit 5:0 of Board Mfg type represent legnth*/ > - size_board = (len & 0x3f); > - if (size_board > 0){ > - if ( strncmp( board_type, "Custom", 6 ) == 0 ){ > - #define NO_MORE_INFO_FIELD 0xc1 > - while ( !feof(input_file) && (board_length > 0) ){ > - if (len != NO_MORE_INFO_FIELD){ > - printf("Additional Custom Mfg. length: 0x%02x\n", len); > - if ( (size_board > 0) && (size_board < (*board_length)) ){ > - unsigned char * additional_data = NULL; > - int i=0; > - additional_data = malloc (size_board); > - if (additional_data != NULL){ > - fread ( additional_data, size_board, 1, input_file ); > - printf("Additional Custom Mfg. Data: %02x", > - additional_data[0]); > - for ( i =1; i<size_board; i++){ > - printf("-%02x", additional_data[i]); > - } > - printf("\n"); > - free (additional_data); > - (*board_length) -= size_board; > - } > - } > - else{ > - printf("No Additional Custom Mfg. %d\n", *board_length); > - board_length = 0; > - } > - } > - else{ > - unsigned char padding; > - /*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; > - /*we reach the end of the record, so its length is set to > 0*/ > - board_length = 0; > - if ( ( padding > 0 ) && ( !feof(input_file) ) ){ > - printf("Unused space: %d (bytes)\n", padding); > - fseek (input_file, padding, SEEK_CUR); > - } > - if ( !feof(input_file) ){ > - unsigned char checksum = 0; > - fread ( &checksum, 1, 1, input_file ); > - printf("Checksum: 0x%02x\n", checksum); > + /* Board length*/ > + if ( !feof(input_file) ){ > + fread ( &len, 1, 1, input_file ); > + (*board_length)--; > + } > + /* Board Data */ > + if ( feof(input_file) ) { > + printf("No Board Data found!\n"); > + goto out; > + } > > - } > - } > - } > - } > - else{ > - unsigned char * data; > - unsigned int i=0; > - #define TYPE_CODE 0xc0 /*Language code*/ > + /*Bit 5:0 of Board Mfg type represent legnth*/ > + size_board = (len & 0x3f); > + if (size_board == 0) { > + printf("%s: None\n", board_type); > + goto out; > + } > > - data = malloc (size_board); > - fread ( data, size_board, 1, input_file ); > - printf("%s type: 0x%02x\n", board_type, len); > - printf("%s: ", board_type); > - for ( i = 0; i < size_board; 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"); > - free (data); > - (*board_length) -= size_board; > - file_offset = ftell (input_file); > - } > - } > - else{ > - printf("%s: None\n", board_type); > - file_offset = ftell (input_file); > - } > - } > + if ( strncmp( board_type, "Custom", 6 ) != 0 ) { > + unsigned char *data; > + unsigned int i=0; > +#define TYPE_CODE 0xc0 /*Language code*/ > + > + data = malloc (size_board); > + fread ( data, size_board, 1, input_file ); > + printf("%s type: 0x%02x\n", board_type, len); > + printf("%s: ", board_type); > + for ( i = 0; i < size_board; 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"); > + free (data); > + (*board_length) -= size_board; > + goto out; > + } > +#define NO_MORE_INFO_FIELD 0xc1 > + while ( !feof(input_file) ) { > + if (len == NO_MORE_INFO_FIELD) { > + unsigned char padding; > + /* 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; > + if ( ( padding > 0 ) && ( !feof(input_file) ) ){ > + printf("Unused space: %d (bytes)\n", padding); > + fseek (input_file, padding, SEEK_CUR); > + } > + if ( !feof(input_file) ){ > + unsigned char checksum = 0; > + fread ( &checksum, 1, 1, input_file ); > + 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)) ) { > + unsigned char * additional_data = NULL; > + unsigned int i=0; > + additional_data = malloc (size_board); > + if (additional_data == NULL) { > + printf("Failed to allocate memory size %d!\n", > + size_board); > + goto out; > + } > + > + fread ( additional_data, size_board, 1, input_file ); > + printf("Additional Custom Mfg. Data: %02x", > + additional_data[0]); > + for (i = 1; i < size_board; i++){ > + printf("-%02x", additional_data[i]); > + } > + printf("\n"); > + free (additional_data); > + (*board_length) -= size_board; > + } > + else { > + printf("No Additional Custom Mfg. %d\n", > *board_length); > + file_offset = ftell (input_file); > + return file_offset; > + } > + } > > - return file_offset; > +out: > + file_offset = ftell(input_file); > + return file_offset; > } > > /************************************************************************** > -- > 1.7.7 > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_d2d_mar > _______________________________________________ > Ipmitool-devel mailing list > Ipmitool-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ipmitool-devel
0005-Fixed-bug-in-ipmi_ek_display_board_info_area.series8.mod.patch
Description: Binary data
------------------------------------------------------------------------------ Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________ Ipmitool-devel mailing list Ipmitool-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ipmitool-devel