[V2] fwts_summary: check for list creation failure
diff mbox series

Message ID 20190610101220.27222-1-colin.king@canonical.com
State Accepted
Headers show
Series
  • [V2] fwts_summary: check for list creation failure
Related show

Commit Message

Colin King June 10, 2019, 10:12 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Check for null pointer when creating a new list.

Addresses-Coverity: ("Dereference null return")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_summary.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Alex Hung June 10, 2019, 8:28 p.m. UTC | #1
On 2019-06-10 3:12 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Check for null pointer when creating a new list.
> 
> Addresses-Coverity: ("Dereference null return")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_summary.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/lib/src/fwts_summary.c b/src/lib/src/fwts_summary.c
> index 625dcd2d..041df5ad 100644
> --- a/src/lib/src/fwts_summary.c
> +++ b/src/lib/src/fwts_summary.c
> @@ -233,6 +233,11 @@ int fwts_summary_report(fwts_framework *fw, fwts_list *test_list)
>  		fwts_list_link *item;
>  		fwts_list *sorted = fwts_list_new();
>  
> +		if (!sorted) {
> +			fwts_log_error(fw, "Out of memory allocating test summary list");
> +			return FWTS_ERROR;
> +		}
> +
>  		fwts_list_foreach(item, test_list)
>  			fwts_list_add_ordered(sorted, fwts_list_data(fwts_framework_test *,item), fwts_framework_compare_test_name);
>  
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
ivanhu June 11, 2019, 5:43 a.m. UTC | #2
On 6/10/19 6:12 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Check for null pointer when creating a new list.
>
> Addresses-Coverity: ("Dereference null return")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_summary.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/src/lib/src/fwts_summary.c b/src/lib/src/fwts_summary.c
> index 625dcd2d..041df5ad 100644
> --- a/src/lib/src/fwts_summary.c
> +++ b/src/lib/src/fwts_summary.c
> @@ -233,6 +233,11 @@ int fwts_summary_report(fwts_framework *fw, fwts_list *test_list)
>  		fwts_list_link *item;
>  		fwts_list *sorted = fwts_list_new();
>  
> +		if (!sorted) {
> +			fwts_log_error(fw, "Out of memory allocating test summary list");
> +			return FWTS_ERROR;
> +		}
> +
>  		fwts_list_foreach(item, test_list)
>  			fwts_list_add_ordered(sorted, fwts_list_data(fwts_framework_test *,item), fwts_framework_compare_test_name);
>  


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

Patch
diff mbox series

diff --git a/src/lib/src/fwts_summary.c b/src/lib/src/fwts_summary.c
index 625dcd2d..041df5ad 100644
--- a/src/lib/src/fwts_summary.c
+++ b/src/lib/src/fwts_summary.c
@@ -233,6 +233,11 @@  int fwts_summary_report(fwts_framework *fw, fwts_list *test_list)
 		fwts_list_link *item;
 		fwts_list *sorted = fwts_list_new();
 
+		if (!sorted) {
+			fwts_log_error(fw, "Out of memory allocating test summary list");
+			return FWTS_ERROR;
+		}
+
 		fwts_list_foreach(item, test_list)
 			fwts_list_add_ordered(sorted, fwts_list_data(fwts_framework_test *,item), fwts_framework_compare_test_name);