arch/x86/smbios: Consider corner case of Part Number

In case of all DMI Type 17 to be empty, the strip trailing whitespace
code will have a zero length Part Number entry, which will cause
exception when using (len - 1) where len is zero. Add extra code to
cover this corner case.

BUG=b:76452395
TEST=Boot up fine with meowth platform, without this patch system will
get stuck at "Create SMBIOS type 17".

Change-Id: Id870c983584771dc1b60b1c99e95bbe7c0d25c4c
Signed-off-by: Lijian Zhao <lijian.zhao@intel.com>
Reviewed-on: https://review.coreboot.org/25377
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Richard Spiegel <richard.spiegel@silverbackltd.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Lijian Zhao 2018-03-26 18:27:02 -07:00 committed by Aaron Durbin
parent c2a9f0cf76
commit b1fc13ac9a
1 changed files with 6 additions and 3 deletions

View File

@ -232,16 +232,19 @@ static void smbios_fill_dimm_part_number(const char *part_number,
len = strlen(trimmed_part_number);
invalid = 0; /* assume valid */
for (i = 0; i < len - 1; i++) {
for (i = 0; i < len; i++) {
if (trimmed_part_number[i] < ' ') {
invalid = 1;
trimmed_part_number[i] = '*';
}
}
if (invalid) {
if (len == 0) {
/* Null String in Part Number will have "None" instead. */
t->part_number = smbios_add_string(t->eos, "None");
} else if (invalid) {
char string_buffer[trimmed_buffer_size +
10 /* strlen("Invalid ()") */];
10 /* strlen("Invalid ()") */];
snprintf(string_buffer, sizeof(string_buffer), "Invalid (%s)",
trimmed_part_number);