From b1fc13ac9af0a74fc206991775933c19379058ba Mon Sep 17 00:00:00 2001 From: Lijian Zhao Date: Mon, 26 Mar 2018 18:27:02 -0700 Subject: 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 Reviewed-on: https://review.coreboot.org/25377 Reviewed-by: Aaron Durbin Reviewed-by: Richard Spiegel Tested-by: build bot (Jenkins) --- src/arch/x86/smbios.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c index 70793741fa..7e776373c4 100644 --- a/src/arch/x86/smbios.c +++ b/src/arch/x86/smbios.c @@ -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); -- cgit v1.2.3