Fixes #496: Add NULL check for malloc in get_option_as_string to prevent potential crashes from unhandled memory allocation failures.
Signed-off-by: Abhinav Srivastava atg271@gmail.com --- payloads/libpayload/drivers/options.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/payloads/libpayload/drivers/options.c b/payloads/libpayload/drivers/options.c index b6d234222d..7571fd739a 100644 --- a/payloads/libpayload/drivers/options.c +++ b/payloads/libpayload/drivers/options.c @@ -318,6 +318,9 @@ int get_option_as_string(const struct nvram_accessor *nvram, struct cb_cmos_opti
/* extra byte to ensure 0-terminated strings */ raw = malloc(cmos_length+1); + if (!raw) { + return -1; + } memset(raw, 0, cmos_length+1);
int ret = get_option_with(nvram, option_table, raw, name);