From 8781dd0e6185b1d82951e313029e0ab40f1936ad Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 6 Dec 2022 23:05:06 +0100 Subject: [PATCH] Fix overly large allocations of MPIs The second argument of ASSERT_ALLOC is a number of array elements, not a number of bytes. Signed-off-by: Gilles Peskine --- tests/suites/test_suite_bignum_random.function | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/suites/test_suite_bignum_random.function b/tests/suites/test_suite_bignum_random.function index 7a6607328..c8bca6e7c 100644 --- a/tests/suites/test_suite_bignum_random.function +++ b/tests/suites/test_suite_bignum_random.function @@ -82,9 +82,9 @@ void mpi_core_random_basic( int min, char *bound_bytes, int expected_ret ) TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &upper_bound, &limbs, bound_bytes ) ); - ASSERT_ALLOC( lower_bound, limbs * ciL ); + ASSERT_ALLOC( lower_bound, limbs ); lower_bound[0] = min; - ASSERT_ALLOC( result, limbs * ciL ); + ASSERT_ALLOC( result, limbs ); TEST_EQUAL( expected_ret, mbedtls_mpi_core_random( result, min, upper_bound, limbs, @@ -121,7 +121,7 @@ void mpi_random_values( int min, char *max_hex ) TEST_EQUAL( 0, mbedtls_test_read_mpi( &max_legacy, max_hex ) ); size_t limbs = max_legacy.n; - ASSERT_ALLOC( R_core, limbs * ciL ); + ASSERT_ALLOC( R_core, limbs ); /* Call the legacy function and the core function with the same random * stream. */ @@ -180,7 +180,7 @@ void mpi_random_many( int min, char *bound_hex, int iterations ) TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &upper_bound, &limbs, bound_hex ) ); - ASSERT_ALLOC( result, limbs * ciL ); + ASSERT_ALLOC( result, limbs ); n_bits = mbedtls_mpi_core_bitlen( upper_bound, limbs ); /* Consider a bound "small" if it's less than 2^5. This value is chosen