From e11e81413d46577503d20a93ce7e791bf4324d2b Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 22 Apr 2021 15:28:56 +0100 Subject: [PATCH] Improve documentation for error code checking Improve comments explaining error code checking, fix incorrect comments and make a small formatting fix. Signed-off-by: Chris Jones --- include/mbedtls/error.h | 2 +- library/ssl_cookie.c | 2 +- tests/src/helpers.c | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 3d8a5eac0..52b818808 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -122,7 +122,7 @@ extern "C" { /** * \brief Combines a high-level and low-level error code together. * - * Wrapper function for mbedtls_err_add_ext(). See that function for + * Wrapper macro for mbedtls_error_add_ext(). See that function for * more details. */ #define MBEDTLS_ERROR_ADD( high, low ) \ diff --git a/library/ssl_cookie.c b/library/ssl_cookie.c index b64c354e6..69d1b3287 100644 --- a/library/ssl_cookie.c +++ b/library/ssl_cookie.c @@ -220,7 +220,7 @@ int mbedtls_ssl_cookie_check( void *p_ctx, #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR , + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR, MBEDTLS_ERR_THREADING_MUTEX_ERROR ) ); #endif diff --git a/tests/src/helpers.c b/tests/src/helpers.c index b54661195..4923e3c68 100644 --- a/tests/src/helpers.c +++ b/tests/src/helpers.c @@ -298,22 +298,34 @@ void mbedtls_test_err_add_check( int high, int low, * h = high level error code (includes high and module error codes). * l = low level error code. */ - if ( high > -0x1000 && high != 0 ) // high < 0001000000000000 + if ( high > -0x1000 && high != 0 ) + /* high < 0001000000000000 + * No high level error bits are set. + */ { mbedtls_test_fail( "'high' is not a high-level error code", line, file ); } - else if ( high < -0x7F80 ) // high > 0111111110000000 + else if ( high < -0x7F80 ) + /* high > 0111111110000000 + * Error code is larger than the greatest high + module level error. + */ { mbedtls_test_fail( "'high' error code is greater than 15 bits", line, file ); } - else if ( ( high & 0x7F ) != 0 ) // high & 0000000001111111 + else if ( ( high & 0x7F ) != 0 ) + /* high & 0000000001111111 + * Error code contains low level error code bits. + */ { mbedtls_test_fail( "'high' contains a low-level error code", line, file ); } - else if ( low < -0x007F ) // low > 0000000001111111 + else if ( low < -0x007F ) + /* low > 0000000001111111 + * Error code contains high or module level error code bits. + */ { mbedtls_test_fail( "'low' error code is greater than 7 bits", line, file );