From a203c38576cd455740fc8581dbb680e264be8e7a Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 29 Jan 2021 14:56:20 +0000 Subject: [PATCH] Expand error addition checks Add new checks and specific error messages to `mbedtls_test_err_add_check`. This should now catch all types of error when combining error codes and provide a specific error message to explain what occured. Signed-off-by: Chris Jones --- tests/src/helpers.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/src/helpers.c b/tests/src/helpers.c index d88ef43f0..9c981de67 100644 --- a/tests/src/helpers.c +++ b/tests/src/helpers.c @@ -287,10 +287,34 @@ void mbedtls_param_failed( const char *failure_condition, void mbedtls_test_err_add_check( int high, int low, const char *file, int line ) { - if ( high > -0x1000 || low < -0x007F ) + if ( high > -0x1000 ) { - mbedtls_fprintf( stderr, "\nIncorrect error code addition at %s:%d\n", - file, line ); + mbedtls_fprintf( stderr, "\n'high' is not a high-level error code - " + "%s:%d\n", file, line ); + mbedtls_exit( 1 ); + } + else if ( high < -0x7F80 ) + { + mbedtls_fprintf( stderr, "\n'high' is greater than 16-bits - " + "%s:%d\n", file, line ); + mbedtls_exit( 1 ); + } + else if ( ( high & 0x7F ) != 0 ) + { + mbedtls_fprintf( stderr, "\n'high' contains a low-level error code - " + "%s:%d\n", file, line ); + mbedtls_exit( 1 ); + } + else if ( low < -0x007F ) + { + mbedtls_fprintf( stderr, "\n'low' is greater than 8-bits - " + "%s:%d\n", file, line ); + mbedtls_exit( 1 ); + } + else if ( low > 0 ) + { + mbedtls_fprintf( stderr, "\n'low' is zero or greater - " + "%s:%d\n", file, line ); mbedtls_exit( 1 ); } }