mb/prodrive/hermes: Harden `eeprom_read_serial()`
The `eeprom_read_serial()` function could return a non-NULL terminated string if the serial in EEPROM has `HERMES_SN_PN_LENGTH` (32) non-NULL characters. Make this impossible by adding an additional character for a NULL byte in the static buffer, which always gets set to 0 (NULL). Change-Id: I306fe1b6dd3836156afca786e352d2a7dca0d77c Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/68322 Reviewed-by: Patrick Georgi <patrick@coreboot.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net>
This commit is contained in:
parent
549c2cd24f
commit
cdc156ebd1
|
@ -127,10 +127,10 @@ struct eeprom_bmc_settings *get_bmc_settings(void)
|
|||
|
||||
const char *eeprom_read_serial(const size_t offset, const char *const fallback)
|
||||
{
|
||||
static char serial_no[HERMES_SN_PN_LENGTH] = { 0 };
|
||||
static char serial_no[HERMES_SN_PN_LENGTH + 1] = { 0 };
|
||||
memset(serial_no, 0, sizeof(serial_no));
|
||||
|
||||
if (eeprom_read_buffer(serial_no, offset, sizeof(serial_no)) == 0)
|
||||
if (eeprom_read_buffer(serial_no, offset, HERMES_SN_PN_LENGTH) == 0)
|
||||
return serial_no;
|
||||
else
|
||||
return fallback;
|
||||
|
|
Loading…
Reference in New Issue