ID: 308 - "fru edit" no longer works for non-zero fields

1. Warnings about "FRU Area Length" based on uninitialized (malloc'd) memory
contents (due to fru->max_read_size not being initialized, left at 0) and
fru_data not being zeroed after malloc() in ipmi_fru_set_field_string().

2. "fru edit" commands for any field index other than 0 would fail (with "Field
not found !" error) due to a couple offset and length calculation errors (for
all the supported "area" types) in ipmi_fru_set_field_string().

3. "fru edit" commands would corrupt the FRU Inventory Area due to incorrect
"source offset" value being specified in write_fru_area() call in
impi_fru_set_field_string().

Commit for Rob Swindell
This commit is contained in:
Zdenek Styblik 2014-04-25 20:48:40 +02:00
parent 4f0967779e
commit 166ae1da23

View File

@ -641,7 +641,7 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
fru->max_read_size = 255; fru->max_read_size = 255;
} else { } else {
/* subtract 1 byte for bytes count */ /* subtract 1 byte for bytes count */
fru->max_write_size = max_rs_size - 1; fru->max_read_size = max_rs_size - 1;
} }
/* check word access */ /* check word access */
@ -4717,22 +4717,22 @@ f_type, uint8_t f_index, char *f_string)
if (f_type == 'c' ) { if (f_type == 'c' ) {
header_offset = (header.offset.chassis * 8); header_offset = (header.offset.chassis * 8);
read_fru_area(intf ,&fru, fruId, header_offset , 3 , fru_data); read_fru_area(intf ,&fru, fruId, header_offset , 3 , fru_data);
fru_field_offset = (header.offset.chassis * 8) + 3; fru_field_offset = 3;
fru_section_len = *(fru_data + header_offset + 1) * 8; fru_section_len = *(fru_data + 1) * 8;
} }
/* Board type field */ /* Board type field */
else if (f_type == 'b' ) { else if (f_type == 'b' ) {
header_offset = (header.offset.board * 8); header_offset = (header.offset.board * 8);
read_fru_area(intf ,&fru, fruId, header_offset , 3 , fru_data); read_fru_area(intf ,&fru, fruId, header_offset , 3 , fru_data);
fru_field_offset = (header.offset.board * 8) + 6; fru_field_offset = 6;
fru_section_len = *(fru_data + header_offset + 1) * 8; fru_section_len = *(fru_data + 1) * 8;
} }
/* Product type field */ /* Product type field */
else if (f_type == 'p' ) { else if (f_type == 'p' ) {
header_offset = (header.offset.product * 8); header_offset = (header.offset.product * 8);
read_fru_area(intf ,&fru, fruId, header_offset , 3 , fru_data); read_fru_area(intf ,&fru, fruId, header_offset , 3 , fru_data);
fru_field_offset = (header.offset.product * 8) + 3; fru_field_offset = 3;
fru_section_len = *(fru_data + header_offset + 1) * 8; fru_section_len = *(fru_data + 1) * 8;
} }
else else
{ {
@ -4782,8 +4782,8 @@ f_type, uint8_t f_index, char *f_string)
checksum = (~checksum) + 1; checksum = (~checksum) + 1;
fru_data[header_offset + fru_section_len - 1] = checksum; fru_data[header_offset + fru_section_len - 1] = checksum;
/* Write the updated section to the FRU data */ /* Write the updated section to the FRU data; source offset: */
if( write_fru_area(intf, &fru, fruId, header_offset, if( write_fru_area(intf, &fru, fruId, 0,
header_offset, fru_section_len, fru_data) < 0 ) header_offset, fru_section_len, fru_data) < 0 )
{ {
printf("Write to FRU data failed.\n"); printf("Write to FRU data failed.\n");