ID: 3608765 - Fixed bug reading length in fru info on big endian machines

Fixed bugs in ipmi_ek_display_chassis_info_area(),
ipmi_ek_display_product_info_area(), and
ipmi_ekanalyzer_fru_file2structure() where fread was being called to
read one byte of data into a int or long data type. This would result
in the value being byte swapped since the byte was read into the most
significant byte of the int (ie byte 0) on big endian machines.

Commit for Dan Gora
This commit is contained in:
Zdenek Styblik 2013-04-18 08:27:33 +00:00
parent de4de4fc96
commit 1e96d20277

View File

@ -2550,6 +2550,7 @@ static void
ipmi_ek_display_chassis_info_area(FILE * input_file, long offset) ipmi_ek_display_chassis_info_area(FILE * input_file, long offset)
{ {
unsigned char data = 0; unsigned char data = 0;
unsigned char ch_len = 0;
unsigned char ch_type = 0; unsigned char ch_type = 0;
unsigned int len; unsigned int len;
size_t file_offset; size_t file_offset;
@ -2573,10 +2574,12 @@ ipmi_ek_display_chassis_info_area(FILE * input_file, long offset)
if (feof(input_file)) { if (feof(input_file)) {
return; return;
} }
/* Have to read this into a char or else
fread(&len, 1, 1, input_file); * it ends up byte swapped on big endian machines
*/
fread(&ch_len, 1, 1, input_file);
/* len is in factor of 8 bytes */ /* len is in factor of 8 bytes */
len = len * 8; len = ch_len * 8;
printf("Area Length: %d\n", len); printf("Area Length: %d\n", len);
len -= 2; len -= 2;
if (feof(input_file)) { if (feof(input_file)) {
@ -2748,6 +2751,7 @@ out:
static void static void
ipmi_ek_display_product_info_area(FILE * input_file, long offset) ipmi_ek_display_product_info_area(FILE * input_file, long offset)
{ {
unsigned char ch_len = 0;
unsigned char data = 0; unsigned char data = 0;
unsigned int len; unsigned int len;
size_t file_offset = ftell(input_file); size_t file_offset = ftell(input_file);
@ -2771,10 +2775,12 @@ ipmi_ek_display_product_info_area(FILE * input_file, long offset)
if (feof(input_file)) { if (feof(input_file)) {
return; return;
} }
/* Have to read this into a char or else
fread(&len, 1, 1, input_file); * it ends up byte swapped on big endian machines
*/
fread(&ch_len, 1, 1, input_file);
/* length is in factor of 8 bytes */ /* length is in factor of 8 bytes */
len = len * 8; len = ch_len * 8;
printf("Area Length: %d\n", len); printf("Area Length: %d\n", len);
len -= 2; /* -1 byte of format version and -1 byte itself */ len -= 2; /* -1 byte of format version and -1 byte itself */
if (feof(input_file)) { if (feof(input_file)) {
@ -3904,8 +3910,9 @@ ipmi_ekanalyzer_fru_file2structure(char * filename,
{ {
int return_status = ERROR_STATUS; int return_status = ERROR_STATUS;
FILE * input_file; FILE * input_file;
char data;
unsigned char last_record = 0; unsigned char last_record = 0;
long multi_offset = 0; int multi_offset = 0;
int record_count = 0; int record_count = 0;
input_file = fopen(filename, "r"); input_file = fopen(filename, "r");
@ -3915,15 +3922,15 @@ ipmi_ekanalyzer_fru_file2structure(char * filename,
} }
fseek(input_file, START_DATA_OFFSET, SEEK_SET); fseek(input_file, START_DATA_OFFSET, SEEK_SET);
fread(&multi_offset, 1, 1, input_file); fread(&data, 1, 1, input_file);
if (multi_offset < 1) { if (data < 1) {
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n", lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
filename); filename);
fclose(input_file); fclose(input_file);
return OK_STATUS; return OK_STATUS;
} }
/* the offset value is in multiple of 8 bytes. */ /* the offset value is in multiple of 8 bytes. */
multi_offset = multi_offset * 8; multi_offset = data * 8;
if (verbose == LOG_DEBUG) { if (verbose == LOG_DEBUG) {
printf("start multi offset = 0x%02lx\n", multi_offset); printf("start multi offset = 0x%02lx\n", multi_offset);
} }