libpayload/option table: Don't pad string entries with garbage

set_option_with() expects a buffer of the exact size of the option.

Change-Id: I21332394f88cf2daa4f733a544627d6d3c6ef26c
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/31348
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Nico Huber 2019-01-30 14:29:42 +01:00 committed by Patrick Georgi
parent 8110f46fcc
commit 5c76ed66b8
1 changed files with 5 additions and 1 deletions

View File

@ -357,7 +357,11 @@ int set_option_from_string(const struct nvram_accessor *nvram, struct cb_cmos_op
*(u64*)raw = strtoull(value, NULL, 0);
break;
case 's':
raw = strdup(value);
raw = malloc(cmos_entry->length);
if (!raw)
return 1;
memset(raw, 0x00, cmos_entry->length);
strncpy(raw, value, cmos_entry->length);
break;
case 'e':
cmos_enum = lookup_cmos_enum_by_label(option_table, cmos_entry->config_id, value);