diff mbox series

opal: add check for the number of regions

Message ID 20200708203303.1260528-1-colin.king@canonical.com
State Accepted
Headers show
Series opal: add check for the number of regions | expand

Commit Message

Colin Ian King July 8, 2020, 8:33 p.m. UTC
From: Colin Ian King <colin.king@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@canonical.com>
---
 src/opal/reserv_mem.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Alex Hung July 8, 2020, 8:56 p.m. UTC | #1
On 2020-07-08 2:33 p.m., Colin King wrote:
> From: Colin Ian King <colin.king@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@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,
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu July 13, 2020, 1:56 a.m. UTC | #2
On 7/9/20 4:33 AM, Colin King wrote:
> From: Colin Ian King <colin.king@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@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,
> 


Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

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,