[PATCH] opal: add check for the number of regions

Colin King colin.king at canonical.com
Wed Jul 8 20:33:03 UTC 2020


From: Colin Ian King <colin.king at canonical.com>

Add a sanity check for the number of regions, the function
fwts_dt_stringlist_count can return 0 or -ve values and this
will cause issues with a later malloc.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/opal/reserv_mem.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/opal/reserv_mem.c b/src/opal/reserv_mem.c
index f243fb2e..5c15a7fc 100644
--- a/src/opal/reserv_mem.c
+++ b/src/opal/reserv_mem.c
@@ -143,6 +143,11 @@ static int reserv_mem_limits_test(fwts_framework *fw)
 	/* Get the number of memory reserved regions */
 	nr_regions = fwts_dt_stringlist_count(fw, fw->fdt, offset,
 				"reserved-names");
+	if (nr_regions < 0) {
+		fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTNoRegions",
+			"DT No regions");
+		return FWTS_ERROR;
+	}
 
 	/* Check for the reservd-names property */
 	region_names = (const char *)fdt_getprop(fw->fdt, offset,
-- 
2.27.0




More information about the fwts-devel mailing list