[PATCH] Add missing malloc check in libpayload

Abhinav Srivastava <[email protected]>
Newsgroups gmane.linux.bios
Message-ID <[email protected]>
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 <[email protected]>
---
 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);
-- 
2.34.1

_______________________________________________
coreboot mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.