From 339b439906f9f36d36dac1ca5ece8eac73e72449 Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Sat, 26 Nov 2022 12:20:41 +0000 Subject: [PATCH] Bignum Mod: remove unused parameter in io_neg test The value was overwritten and the length wasn't used either. This latter could have lead to a buffer overflow as well. Signed-off-by: Janos Follath --- tests/suites/test_suite_bignum_mod.data | 10 +++++----- tests/suites/test_suite_bignum_mod.function | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/suites/test_suite_bignum_mod.data b/tests/suites/test_suite_bignum_mod.data index 8579becfa..2ea4a5833 100644 --- a/tests/suites/test_suite_bignum_mod.data +++ b/tests/suites/test_suite_bignum_mod.data @@ -57,19 +57,19 @@ Test mbedtls_mpi_residue_setup #8 r > m mpi_residue_setup:"fe":"ff":-4 Test mbedtls_mpi_mod_io_neg #1 input_r < modulo m -mpi_mod_io_neg:"fe":"01":"fd":0 +mpi_mod_io_neg:"fe":"fd":0 Test mbedtls_mpi_mod_io_neg #2 input_r == modulo m -mpi_mod_io_neg:"fe":"01":"fe":MBEDTLS_ERR_MPI_BAD_INPUT_DATA +mpi_mod_io_neg:"fe":"fe":MBEDTLS_ERR_MPI_BAD_INPUT_DATA Test mbedtls_mpi_mod_io_neg #3 input_r > modulo m -mpi_mod_io_neg:"fe":"01":"ff":MBEDTLS_ERR_MPI_BAD_INPUT_DATA +mpi_mod_io_neg:"fe":"ff":MBEDTLS_ERR_MPI_BAD_INPUT_DATA Test mbedtls_mpi_mod_io_neg #4 input_r too large to fit -mpi_mod_io_neg:"fe":"01":"ffffffffffffffffff":MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL +mpi_mod_io_neg:"fe":"ffffffffffffffffff":MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL Test mbedtls_mpi_mod_io_neg #5 Sucesfull read / output buffer too small -mpi_mod_io_neg:"7ffffffffffffffffffffffffffffff1":"7ffffffffffffffffffffffffffffff0":"ffff":0 +mpi_mod_io_neg:"7ffffffffffffffffffffffffffffff1":"ffff":0 Test mbedtls_mpi_mod_io #1 N: "11" A: "119". mpi_mod_io:"000000000000000b":"0000000000000000":MBEDTLS_MPI_MOD_EXT_REP_BE diff --git a/tests/suites/test_suite_bignum_mod.function b/tests/suites/test_suite_bignum_mod.function index 1d6b850b5..6a70e7287 100644 --- a/tests/suites/test_suite_bignum_mod.function +++ b/tests/suites/test_suite_bignum_mod.function @@ -114,11 +114,10 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mpi_mod_io_neg( char * input_N, char * input_R, data_t * buf, int ret ) +void mpi_mod_io_neg( char * input_N, data_t * buf, int ret ) { mbedtls_mpi_uint *N = NULL; mbedtls_mpi_uint *R = NULL; - size_t n_limbs, r_limbs; mbedtls_mpi_mod_modulus m; mbedtls_mpi_mod_residue r; @@ -127,8 +126,10 @@ void mpi_mod_io_neg( char * input_N, char * input_R, data_t * buf, int ret ) mbedtls_mpi_mod_modulus_init( &m ); + size_t n_limbs; TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) ); - TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &R, &r_limbs, input_R ) ); + size_t r_limbs = n_limbs; + ASSERT_ALLOC( R, r_limbs ); /* modulo->p == NULL || residue->p == NULL ( m has not been set-up ) */ TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA, @@ -139,7 +140,7 @@ void mpi_mod_io_neg( char * input_N, char * input_R, data_t * buf, int ret ) TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs, MBEDTLS_MPI_MOD_REP_MONTGOMERY ) ); - TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &r, &m, R , n_limbs ) ); + TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &r, &m, R , r_limbs ) ); /* modulo->p == NULL || residue->p == NULL ( m has been set-up ) */ TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,