[Skiboot] [PATCH trivial 1/2] opal-prd: Check malloc return value

Vasant Hegde hegdevasant at linux.vnet.ibm.com
Tue Apr 9 21:51:24 AEST 2019


Signed-off-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
---
 external/opal-prd/opal-prd.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/external/opal-prd/opal-prd.c b/external/opal-prd/opal-prd.c
index 1452a17fa..41d13ecf7 100644
--- a/external/opal-prd/opal-prd.c
+++ b/external/opal-prd/opal-prd.c
@@ -1017,6 +1017,10 @@ static int open_and_read(const char *path, void **bufp, int *lenp)
 	}
 
 	buf = malloc(statbuf.st_size);
+	if (!buf) {
+		close(fd);
+		return -1;
+	}
 
 	for (rc = bytes = 0; bytes < statbuf.st_size; bytes += rc) {
 		rc = read(fd, buf + bytes, statbuf.st_size - bytes);
-- 
2.14.3



More information about the Skiboot mailing list