From ec5685f1ee4a284ceda566da101bf0d0e84b8486 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Fri, 30 Sep 2022 14:41:13 +0200 Subject: [PATCH] Use exact-size buffers for inputs and outputs to library functions in tests Signed-off-by: Gabor Mezei --- tests/suites/test_suite_mpi.function | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index f90fee311..cf22e3736 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -890,12 +890,13 @@ void mpi_mod_raw_cond_assign( data_t * input_X, #define MAX_LEN 64 mbedtls_mpi_uint *X = NULL; mbedtls_mpi_uint *Y = NULL; - mbedtls_mpi_uint buff_m[MAX_LEN]; + mbedtls_mpi_uint *buff_m = NULL; mbedtls_mpi_mod_modulus m; size_t limbs_X = CHARS_TO_LIMBS( input_X->len ); size_t limbs_Y = CHARS_TO_LIMBS( input_Y->len ); size_t len_X = limbs_X * sizeof( mbedtls_mpi_uint ); size_t len_Y = limbs_Y * sizeof( mbedtls_mpi_uint ); + size_t len_m = len_Y; TEST_ASSERT( limbs_X <= MAX_LEN ); TEST_ASSERT( limbs_Y <= MAX_LEN ); @@ -903,7 +904,8 @@ void mpi_mod_raw_cond_assign( data_t * input_X, ASSERT_ALLOC( X, len_X ); ASSERT_ALLOC( Y, len_Y ); - memset( buff_m, 0, MAX_LEN * sizeof( mbedtls_mpi_uint ) ); + ASSERT_ALLOC( buff_m, len_m ); + memset( buff_m, 0, len_m ); mbedtls_mpi_mod_modulus_init( &m ); TEST_ASSERT( mbedtls_mpi_mod_modulus_setup( &m, buff_m, limbs_Y, @@ -946,6 +948,7 @@ exit: mbedtls_free( Y ); mbedtls_mpi_mod_modulus_free( &m ); + mbedtls_free( buff_m ); #undef MAX_LEN } @@ -960,7 +963,7 @@ void mpi_mod_raw_cond_swap( data_t * input_X, mbedtls_mpi_uint *tmp_Y = NULL; mbedtls_mpi_uint *X = NULL; mbedtls_mpi_uint *Y = NULL; - mbedtls_mpi_uint buff_m[MAX_LEN]; + mbedtls_mpi_uint *buff_m = NULL; mbedtls_mpi_mod_modulus m; size_t limbs_X = CHARS_TO_LIMBS( input_X->len ); size_t limbs_Y = CHARS_TO_LIMBS( input_Y->len ); @@ -974,7 +977,8 @@ void mpi_mod_raw_cond_swap( data_t * input_X, ASSERT_ALLOC( tmp_X, len_X ); ASSERT_ALLOC( tmp_Y, len_Y ); - memset( buff_m, 0, MAX_LEN * sizeof( mbedtls_mpi_uint ) ); + ASSERT_ALLOC( buff_m, len_m ); + memset( buff_m, 0, len_m ); mbedtls_mpi_mod_modulus_init( &m ); TEST_ASSERT( mbedtls_mpi_mod_modulus_setup( &m, buff_m, limbs_X, @@ -1023,6 +1027,7 @@ exit: mbedtls_free( Y ); mbedtls_mpi_mod_modulus_free( &m ); + mbedtls_free( buff_m ); #undef MAX_LEN }