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 <christopher.jones@arm.com>
This commit is contained in:
Chris Jones 2021-01-29 14:56:20 +00:00
parent ef180af350
commit a203c38576

View file

@ -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 );
}
}