From f25ee7f79d79e1104329d493a66df069e387b23c Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Wed, 19 Dec 2018 16:51:02 +0000 Subject: [PATCH] Fix parameter validation for mbedtls_mpi_lsb() The MPI_VALIDATE_RET() macro cannot be used for parameter validation of mbedtls_mpi_lsb() because this function returns a size_t. Use the underlying MBEDTLS_INTERNAL_VALIDATE_RET() insteaed, returning 0 on failure. Also, add a test for this behaviour. --- library/bignum.c | 2 +- tests/suites/test_suite_mpi.function | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/library/bignum.c b/library/bignum.c index 0d0d922c1..f968a0ad7 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -380,7 +380,7 @@ cleanup: size_t mbedtls_mpi_lsb( const mbedtls_mpi *X ) { size_t i, j, count = 0; - MPI_VALIDATE_RET( X != NULL ); + MBEDTLS_INTERNAL_VALIDATE_RET( X != NULL, 0 ); for( i = 0; i < X->n; i++ ) for( j = 0; j < biL; j++, count++ ) diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index 3379a999d..d1fa5a46c 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -216,6 +216,8 @@ void mpi_invalid_param( ) TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA, mbedtls_mpi_div_int( &X, &X, NULL, 42 ) ); + TEST_INVALID_PARAM_RET( 0, mbedtls_mpi_lsb( NULL ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA, mbedtls_mpi_mod_mpi( NULL, &X, &X ) ); TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,