From fbeb4866f4250a4a23e7afb884a0aa0456d152f8 Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 6 Sep 2022 11:41:35 +1000 Subject: [PATCH] Coverity: explicit null dereference Coverity is being pretty silly here but adding the explicit pointer checks will stop a crash if something goes badly awry. Fixes Coverity 1513706 - 1513709 Reviewed-by: Shane Lontis Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/19136) --- test/list_test.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/list_test.c b/test/list_test.c index 5f89e5c6ad..908634d1f4 100644 --- a/test/list_test.c +++ b/test/list_test.c @@ -53,6 +53,10 @@ static int test_fizzbuzz(void) if (!TEST_size_t_eq(ossl_list_fizz_num(&a), na) || !TEST_size_t_eq(ossl_list_buzz_num(&b), nb) + || !TEST_ptr(ossl_list_fizz_head(&a)) + || !TEST_ptr(ossl_list_fizz_tail(&a)) + || !TEST_ptr(ossl_list_buzz_head(&b)) + || !TEST_ptr(ossl_list_buzz_tail(&b)) || !TEST_int_eq(ossl_list_fizz_head(&a)->n, 3) || !TEST_int_eq(ossl_list_fizz_tail(&a)->n, na * 3) || !TEST_int_eq(ossl_list_buzz_head(&b)->n, nb * 5) @@ -62,8 +66,12 @@ static int test_fizzbuzz(void) ossl_list_buzz_remove(&b, ossl_list_buzz_tail(&b)); if (!TEST_size_t_eq(ossl_list_fizz_num(&a), --na) || !TEST_size_t_eq(ossl_list_buzz_num(&b), --nb) + || !TEST_ptr(ossl_list_fizz_head(&a)) + || !TEST_ptr(ossl_list_buzz_tail(&b)) || !TEST_int_eq(ossl_list_fizz_head(&a)->n, 6) || !TEST_int_eq(ossl_list_buzz_tail(&b)->n, 10) + || !TEST_ptr(ossl_list_fizz_next(ossl_list_fizz_head(&a))) + || !TEST_ptr(ossl_list_fizz_prev(ossl_list_fizz_tail(&a))) || !TEST_int_eq(ossl_list_fizz_next(ossl_list_fizz_head(&a))->n, 9) || !TEST_int_eq(ossl_list_fizz_prev(ossl_list_fizz_tail(&a))->n, 15)) return 0; @@ -133,14 +141,18 @@ static int test_insert(void) ossl_list_int_remove(&l, elem + 2); /* 3 4 5 */ ossl_list_int_remove(&l, elem + 4); /* 3 5 */ ossl_list_int_remove(&l, elem + 3); /* 5 */ - if (!TEST_int_eq(ossl_list_int_head(&l)->n, 5) + if (!TEST_ptr(ossl_list_int_head(&l)) + || !TEST_ptr(ossl_list_int_tail(&l)) + || !TEST_int_eq(ossl_list_int_head(&l)->n, 5) || !TEST_int_eq(ossl_list_int_tail(&l)->n, 5)) return 0; /* Check removing the tail of a two element list works */ ossl_list_int_insert_head(&l, elem); /* 0 5 */ ossl_list_int_remove(&l, elem + 5); /* 0 */ - if (!TEST_int_eq(ossl_list_int_head(&l)->n, 0) + if (!TEST_ptr(ossl_list_int_head(&l)) + || !TEST_ptr(ossl_list_int_tail(&l)) + || !TEST_int_eq(ossl_list_int_head(&l)->n, 0) || !TEST_int_eq(ossl_list_int_tail(&l)->n, 0)) return 0;