mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-03-20 19:21:09 +01:00
Remove MBEDTLS_CHECK_PARAMS option
Signed-off-by: TRodziewicz <tomasz.rodziewicz@mobica.com>
This commit is contained in:
@@ -860,6 +860,9 @@
|
||||
#error "MBEDTLS_ZLIB_SUPPORT was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4031"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS) //no-check-names
|
||||
#error "MBEDTLS_CHECK_PARAMS was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4313"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Avoid warning from -pedantic. This is a convenient place for this
|
||||
|
||||
@@ -255,72 +255,6 @@
|
||||
*/
|
||||
//#define MBEDTLS_DEPRECATED_REMOVED
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CHECK_PARAMS
|
||||
*
|
||||
* This configuration option controls whether the library validates more of
|
||||
* the parameters passed to it.
|
||||
*
|
||||
* When this flag is not defined, the library only attempts to validate an
|
||||
* input parameter if: (1) they may come from the outside world (such as the
|
||||
* network, the filesystem, etc.) or (2) not validating them could result in
|
||||
* internal memory errors such as overflowing a buffer controlled by the
|
||||
* library. On the other hand, it doesn't attempt to validate parameters whose
|
||||
* values are fully controlled by the application (such as pointers).
|
||||
*
|
||||
* When this flag is defined, the library additionally attempts to validate
|
||||
* parameters that are fully controlled by the application, and should always
|
||||
* be valid if the application code is fully correct and trusted.
|
||||
*
|
||||
* For example, when a function accepts as input a pointer to a buffer that may
|
||||
* contain untrusted data, and its documentation mentions that this pointer
|
||||
* must not be NULL:
|
||||
* - The pointer is checked to be non-NULL only if this option is enabled.
|
||||
* - The content of the buffer is always validated.
|
||||
*
|
||||
* When this flag is defined, if a library function receives a parameter that
|
||||
* is invalid:
|
||||
* 1. The function will invoke the macro MBEDTLS_PARAM_FAILED().
|
||||
* 2. If MBEDTLS_PARAM_FAILED() did not terminate the program, the function
|
||||
* will immediately return. If the function returns an Mbed TLS error code,
|
||||
* the error code in this case is MBEDTLS_ERR_xxx_BAD_INPUT_DATA.
|
||||
*
|
||||
* When defining this flag, you also need to arrange a definition for
|
||||
* MBEDTLS_PARAM_FAILED(). You can do this by any of the following methods:
|
||||
* - By default, the library defines MBEDTLS_PARAM_FAILED() to call a
|
||||
* function mbedtls_param_failed(), but the library does not define this
|
||||
* function. If you do not make any other arrangements, you must provide
|
||||
* the function mbedtls_param_failed() in your application.
|
||||
* See `platform_util.h` for its prototype.
|
||||
* - If you enable the macro #MBEDTLS_CHECK_PARAMS_ASSERT, then the
|
||||
* library defines MBEDTLS_PARAM_FAILED(\c cond) to be `assert(cond)`.
|
||||
* You can still supply an alternative definition of
|
||||
* MBEDTLS_PARAM_FAILED(), which may call `assert`.
|
||||
* - If you define a macro MBEDTLS_PARAM_FAILED() before including `config.h`
|
||||
* or you uncomment the definition of MBEDTLS_PARAM_FAILED() in `config.h`,
|
||||
* the library will call the macro that you defined and will not supply
|
||||
* its own version. Note that if MBEDTLS_PARAM_FAILED() calls `assert`,
|
||||
* you need to enable #MBEDTLS_CHECK_PARAMS_ASSERT so that library source
|
||||
* files include `<assert.h>`.
|
||||
*
|
||||
* Uncomment to enable validation of application-controlled parameters.
|
||||
*/
|
||||
//#define MBEDTLS_CHECK_PARAMS
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CHECK_PARAMS_ASSERT
|
||||
*
|
||||
* Allow MBEDTLS_PARAM_FAILED() to call `assert`, and make it default to
|
||||
* `assert`. This macro is only used if #MBEDTLS_CHECK_PARAMS is defined.
|
||||
*
|
||||
* If this macro is not defined, then MBEDTLS_PARAM_FAILED() defaults to
|
||||
* calling a function mbedtls_param_failed(). See the documentation of
|
||||
* #MBEDTLS_CHECK_PARAMS for details.
|
||||
*
|
||||
* Uncomment to allow MBEDTLS_PARAM_FAILED() to call `assert`.
|
||||
*/
|
||||
//#define MBEDTLS_CHECK_PARAMS_ASSERT
|
||||
|
||||
/* \} name SECTION: System support */
|
||||
|
||||
/**
|
||||
@@ -3465,42 +3399,6 @@
|
||||
//#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
|
||||
//#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
|
||||
|
||||
/**
|
||||
* \brief This macro is invoked by the library when an invalid parameter
|
||||
* is detected that is only checked with #MBEDTLS_CHECK_PARAMS
|
||||
* (see the documentation of that option for context).
|
||||
*
|
||||
* When you leave this undefined here, the library provides
|
||||
* a default definition. If the macro #MBEDTLS_CHECK_PARAMS_ASSERT
|
||||
* is defined, the default definition is `assert(cond)`,
|
||||
* otherwise the default definition calls a function
|
||||
* mbedtls_param_failed(). This function is declared in
|
||||
* `platform_util.h` for the benefit of the library, but
|
||||
* you need to define in your application.
|
||||
*
|
||||
* When you define this here, this replaces the default
|
||||
* definition in platform_util.h (which no longer declares the
|
||||
* function mbedtls_param_failed()) and it is your responsibility
|
||||
* to make sure this macro expands to something suitable (in
|
||||
* particular, that all the necessary declarations are visible
|
||||
* from within the library - you can ensure that by providing
|
||||
* them in this file next to the macro definition).
|
||||
* If you define this macro to call `assert`, also define
|
||||
* #MBEDTLS_CHECK_PARAMS_ASSERT so that library source files
|
||||
* include `<assert.h>`.
|
||||
*
|
||||
* Note that you may define this macro to expand to nothing, in
|
||||
* which case you don't have to worry about declarations or
|
||||
* definitions. However, you will then be notified about invalid
|
||||
* parameters only in non-void functions, and void function will
|
||||
* just silently return early on invalid parameters, which
|
||||
* partially negates the benefits of enabling
|
||||
* #MBEDTLS_CHECK_PARAMS in the first place, so is discouraged.
|
||||
*
|
||||
* \param cond The expression that should evaluate to true, but doesn't.
|
||||
*/
|
||||
//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
|
||||
|
||||
/* PSA options */
|
||||
/**
|
||||
* Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the
|
||||
|
||||
@@ -39,78 +39,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
|
||||
/* Allow the user to define MBEDTLS_PARAM_FAILED to something like assert
|
||||
* (which is what our config.h suggests). */
|
||||
#include <assert.h>
|
||||
#endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
|
||||
|
||||
#if defined(MBEDTLS_PARAM_FAILED)
|
||||
/** An alternative definition of MBEDTLS_PARAM_FAILED has been set in config.h.
|
||||
*
|
||||
* This flag can be used to check whether it is safe to assume that
|
||||
* MBEDTLS_PARAM_FAILED() will expand to a call to mbedtls_param_failed().
|
||||
*/
|
||||
#define MBEDTLS_PARAM_FAILED_ALT
|
||||
|
||||
#elif defined(MBEDTLS_CHECK_PARAMS_ASSERT)
|
||||
#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
|
||||
#define MBEDTLS_PARAM_FAILED_ALT
|
||||
|
||||
#else /* MBEDTLS_PARAM_FAILED */
|
||||
#define MBEDTLS_PARAM_FAILED( cond ) \
|
||||
mbedtls_param_failed( #cond, __FILE__, __LINE__ )
|
||||
|
||||
/**
|
||||
* \brief User supplied callback function for parameter validation failure.
|
||||
* See #MBEDTLS_CHECK_PARAMS for context.
|
||||
*
|
||||
* This function will be called unless an alternative treatement
|
||||
* is defined through the #MBEDTLS_PARAM_FAILED macro.
|
||||
*
|
||||
* This function can return, and the operation will be aborted, or
|
||||
* alternatively, through use of setjmp()/longjmp() can resume
|
||||
* execution in the application code.
|
||||
*
|
||||
* \param failure_condition The assertion that didn't hold.
|
||||
* \param file The file where the assertion failed.
|
||||
* \param line The line in the file where the assertion failed.
|
||||
*/
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line );
|
||||
#endif /* MBEDTLS_PARAM_FAILED */
|
||||
|
||||
/* Internal macro meant to be called only from within the library. */
|
||||
#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \
|
||||
do { \
|
||||
if( !(cond) ) \
|
||||
{ \
|
||||
MBEDTLS_PARAM_FAILED( cond ); \
|
||||
return( ret ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
/* Internal macro meant to be called only from within the library. */
|
||||
#define MBEDTLS_INTERNAL_VALIDATE( cond ) \
|
||||
do { \
|
||||
if( !(cond) ) \
|
||||
{ \
|
||||
MBEDTLS_PARAM_FAILED( cond ); \
|
||||
return; \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#else /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
/* Internal macros meant to be called only from within the library. */
|
||||
#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 )
|
||||
#define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 )
|
||||
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
/* Internal helper macros for deprecating API constants. */
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
|
||||
@@ -1028,9 +1028,6 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot )
|
||||
*/
|
||||
if( slot->lock_count != 1 )
|
||||
{
|
||||
#ifdef MBEDTLS_CHECK_PARAMS
|
||||
MBEDTLS_PARAM_FAILED( slot->lock_count == 1 );
|
||||
#endif
|
||||
status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -409,17 +409,6 @@ psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot )
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
/*
|
||||
* As the return error code may not be handled in case of multiple errors,
|
||||
* do our best to report if the lock counter is equal to zero: if
|
||||
* available call MBEDTLS_PARAM_FAILED that may terminate execution (if
|
||||
* called as part of the execution of a unit test suite this will stop the
|
||||
* test suite execution).
|
||||
*/
|
||||
#ifdef MBEDTLS_CHECK_PARAMS
|
||||
MBEDTLS_PARAM_FAILED( slot->lock_count > 0 );
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
}
|
||||
|
||||
|
||||
@@ -81,12 +81,6 @@ static const char * const features[] = {
|
||||
#if defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
"MBEDTLS_DEPRECATED_REMOVED",
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
"MBEDTLS_CHECK_PARAMS",
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
#if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
|
||||
"MBEDTLS_CHECK_PARAMS_ASSERT",
|
||||
#endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
|
||||
#if defined(MBEDTLS_TIMING_ALT)
|
||||
"MBEDTLS_TIMING_ALT",
|
||||
#endif /* MBEDTLS_TIMING_ALT */
|
||||
|
||||
@@ -267,22 +267,6 @@ int query_config( const char *config )
|
||||
}
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
if( strcmp( "MBEDTLS_CHECK_PARAMS", config ) == 0 )
|
||||
{
|
||||
MACRO_EXPANSION_TO_STR( MBEDTLS_CHECK_PARAMS );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
|
||||
if( strcmp( "MBEDTLS_CHECK_PARAMS_ASSERT", config ) == 0 )
|
||||
{
|
||||
MACRO_EXPANSION_TO_STR( MBEDTLS_CHECK_PARAMS_ASSERT );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
|
||||
|
||||
#if defined(MBEDTLS_TIMING_ALT)
|
||||
if( strcmp( "MBEDTLS_TIMING_ALT", config ) == 0 )
|
||||
{
|
||||
|
||||
@@ -44,7 +44,6 @@ my $query_config_file = "./programs/test/query_config.c";
|
||||
# throw errors.
|
||||
my @excluded = qw(
|
||||
MBEDTLS_SSL_CIPHERSUITES
|
||||
MBEDTLS_PARAM_FAILED
|
||||
);
|
||||
my $excluded_re = join '|', @excluded;
|
||||
|
||||
|
||||
@@ -175,95 +175,6 @@ unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen );
|
||||
int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
|
||||
uint32_t a_len, uint32_t b_len );
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *failure_condition;
|
||||
const char *file;
|
||||
int line;
|
||||
}
|
||||
mbedtls_test_param_failed_location_record_t;
|
||||
|
||||
/**
|
||||
* \brief Get the location record of the last call to
|
||||
* mbedtls_test_param_failed().
|
||||
*
|
||||
* \note The call expectation is set up and active until the next call to
|
||||
* mbedtls_test_param_failed_check_expected_call() or
|
||||
* mbedtls_param_failed() that cancels it.
|
||||
*/
|
||||
void mbedtls_test_param_failed_get_location_record(
|
||||
mbedtls_test_param_failed_location_record_t *location_record );
|
||||
|
||||
/**
|
||||
* \brief State that a call to mbedtls_param_failed() is expected.
|
||||
*
|
||||
* \note The call expectation is set up and active until the next call to
|
||||
* mbedtls_test_param_failed_check_expected_call() or
|
||||
* mbedtls_param_failed that cancel it.
|
||||
*/
|
||||
void mbedtls_test_param_failed_expect_call( void );
|
||||
|
||||
/**
|
||||
* \brief Check whether mbedtls_param_failed() has been called as expected.
|
||||
*
|
||||
* \note Check whether mbedtls_param_failed() has been called between the
|
||||
* last call to mbedtls_test_param_failed_expect_call() and the call
|
||||
* to this function.
|
||||
*
|
||||
* \return \c 0 Since the last call to mbedtls_param_failed_expect_call(),
|
||||
* mbedtls_param_failed() has been called.
|
||||
* \c -1 Otherwise.
|
||||
*/
|
||||
int mbedtls_test_param_failed_check_expected_call( void );
|
||||
|
||||
/**
|
||||
* \brief Get the address of the object of type jmp_buf holding the execution
|
||||
* state information used by mbedtls_param_failed() to do a long jump.
|
||||
*
|
||||
* \note If a call to mbedtls_param_failed() is not expected in the sense
|
||||
* that there is no call to mbedtls_test_param_failed_expect_call()
|
||||
* preceding it, then mbedtls_param_failed() will try to restore the
|
||||
* execution to the state stored in the jmp_buf object whose address
|
||||
* is returned by the present function.
|
||||
*
|
||||
* \note This function is intended to provide the parameter of the
|
||||
* setjmp() function to set-up where mbedtls_param_failed() should
|
||||
* long-jump if it has to. It is foreseen to be used as:
|
||||
*
|
||||
* setjmp( mbedtls_test_param_failed_get_state_buf() ).
|
||||
*
|
||||
* \note The type of the returned value is not jmp_buf as jmp_buf is an
|
||||
* an array type (C specification) and a function cannot return an
|
||||
* array type.
|
||||
*
|
||||
* \note The type of the returned value is not jmp_buf* as then the return
|
||||
* value couldn't be used by setjmp(), as its parameter's type is
|
||||
* jmp_buf.
|
||||
*
|
||||
* \return Address of the object of type jmp_buf holding the execution state
|
||||
* information used by mbedtls_param_failed() to do a long jump.
|
||||
*/
|
||||
void* mbedtls_test_param_failed_get_state_buf( void );
|
||||
|
||||
/**
|
||||
* \brief Reset the execution state used by mbedtls_param_failed() to do a
|
||||
* long jump.
|
||||
*
|
||||
* \note If a call to mbedtls_param_failed() is not expected in the sense
|
||||
* that there is no call to mbedtls_test_param_failed_expect_call()
|
||||
* preceding it, then mbedtls_param_failed() will try to restore the
|
||||
* execution state that this function reset.
|
||||
*
|
||||
* \note It is recommended to reset the execution state when the state
|
||||
* is not relevant anymore. That way an unexpected call to
|
||||
* mbedtls_param_failed() will not trigger a long jump with
|
||||
* undefined behavior but rather a long jump that will rather fault.
|
||||
*/
|
||||
void mbedtls_test_param_failed_reset_state( void );
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
#include "test/fake_external_rng_for_test.h"
|
||||
#endif
|
||||
|
||||
@@ -58,10 +58,6 @@
|
||||
* It allows a library function to return a value and return an error
|
||||
* code that can be tested.
|
||||
*
|
||||
* When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
|
||||
* callback, MBEDTLS_PARAM_FAILED(), will be assumed to be a test
|
||||
* failure.
|
||||
*
|
||||
* This macro is not suitable for negative parameter validation tests,
|
||||
* as it assumes the test step will not create an error.
|
||||
*
|
||||
@@ -181,73 +177,6 @@
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS) && !defined(MBEDTLS_PARAM_FAILED_ALT)
|
||||
/**
|
||||
* \brief This macro tests the statement passed to it as a test step or
|
||||
* individual test in a test case. The macro assumes the test will fail
|
||||
* and will generate an error.
|
||||
*
|
||||
* It allows a library function to return a value and tests the return
|
||||
* code on return to confirm the given error code was returned.
|
||||
*
|
||||
* When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
|
||||
* callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
|
||||
* expected failure, and the test will pass.
|
||||
*
|
||||
* This macro is intended for negative parameter validation tests,
|
||||
* where the failing function may return an error value or call
|
||||
* MBEDTLS_PARAM_FAILED() to indicate the error.
|
||||
*
|
||||
* \param PARAM_ERROR_VALUE The expected error code.
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_INVALID_PARAM_RET( PARAM_ERR_VALUE, TEST ) \
|
||||
do { \
|
||||
mbedtls_test_param_failed_expect_call( ); \
|
||||
if( ( ( TEST ) != ( PARAM_ERR_VALUE ) ) || \
|
||||
( mbedtls_test_param_failed_check_expected_call( ) != 0 ) ) \
|
||||
{ \
|
||||
mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
goto exit; \
|
||||
} \
|
||||
mbedtls_test_param_failed_check_expected_call( ); \
|
||||
} while( 0 )
|
||||
|
||||
/**
|
||||
* \brief This macro tests the statement passed to it as a test step or
|
||||
* individual test in a test case. The macro assumes the test will fail
|
||||
* and will generate an error.
|
||||
*
|
||||
* It assumes the library function under test cannot return a value and
|
||||
* assumes errors can only be indicated byt calls to
|
||||
* MBEDTLS_PARAM_FAILED().
|
||||
*
|
||||
* When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
|
||||
* callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
|
||||
* expected failure. If MBEDTLS_CHECK_PARAMS is not enabled, no test
|
||||
* can be made.
|
||||
*
|
||||
* This macro is intended for negative parameter validation tests,
|
||||
* where the failing function can only return an error by calling
|
||||
* MBEDTLS_PARAM_FAILED() to indicate the error.
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_INVALID_PARAM( TEST ) \
|
||||
do { \
|
||||
memcpy( jmp_tmp, mbedtls_test_param_failed_get_state_buf( ), \
|
||||
sizeof( jmp_tmp ) ); \
|
||||
if( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 ) \
|
||||
{ \
|
||||
TEST; \
|
||||
mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
goto exit; \
|
||||
} \
|
||||
mbedtls_test_param_failed_reset_state( ); \
|
||||
} while( 0 )
|
||||
#endif /* MBEDTLS_CHECK_PARAMS && !MBEDTLS_PARAM_FAILED_ALT */
|
||||
|
||||
/**
|
||||
* \brief This macro tests the statement passed to it as a test step or
|
||||
* individual test in a test case. The macro assumes the test will not fail.
|
||||
@@ -256,11 +185,6 @@
|
||||
* assumes errors can only be indicated by calls to
|
||||
* MBEDTLS_PARAM_FAILED().
|
||||
*
|
||||
* When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
|
||||
* callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
|
||||
* expected failure. If MBEDTLS_CHECK_PARAMS is not enabled, no test
|
||||
* can be made.
|
||||
*
|
||||
* This macro is intended to test that functions returning void
|
||||
* accept all of the parameter values they're supposed to accept - eg
|
||||
* that they don't call MBEDTLS_PARAM_FAILED() when a parameter
|
||||
@@ -271,12 +195,6 @@
|
||||
* accept is best done by using TEST_ASSERT() and checking the return
|
||||
* value as well.
|
||||
*
|
||||
* Note: this macro is available even when #MBEDTLS_CHECK_PARAMS is
|
||||
* disabled, as it makes sense to check that the functions accept all
|
||||
* legal values even if this option is disabled - only in that case,
|
||||
* the test is more about whether the function segfaults than about
|
||||
* whether it invokes MBEDTLS_PARAM_FAILED().
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_VALID_PARAM( TEST ) \
|
||||
|
||||
@@ -1825,38 +1825,6 @@ component_build_psa_accel_key_type_rsa_public_key() {
|
||||
make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
|
||||
}
|
||||
|
||||
component_test_check_params_functionality () {
|
||||
msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
|
||||
scripts/config.py full # includes CHECK_PARAMS
|
||||
# Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
|
||||
scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
|
||||
make CC=gcc CFLAGS='-Werror -O1' all test
|
||||
}
|
||||
|
||||
component_test_check_params_without_platform () {
|
||||
msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
|
||||
scripts/config.py full # includes CHECK_PARAMS
|
||||
# Keep MBEDTLS_PARAM_FAILED as assert.
|
||||
scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
|
||||
scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
|
||||
scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
|
||||
scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
|
||||
scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
|
||||
scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
|
||||
scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
|
||||
scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
|
||||
scripts/config.py unset MBEDTLS_PLATFORM_C
|
||||
make CC=gcc CFLAGS='-Werror -O1' all test
|
||||
}
|
||||
|
||||
component_test_check_params_silent () {
|
||||
msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
|
||||
scripts/config.py full # includes CHECK_PARAMS
|
||||
# Set MBEDTLS_PARAM_FAILED to nothing.
|
||||
sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
|
||||
make CC=gcc CFLAGS='-Werror -O1' all test
|
||||
}
|
||||
|
||||
component_test_no_platform () {
|
||||
# Full configuration build, without platform support, file IO and net sockets.
|
||||
# This should catch missing mbedtls_printf definitions, and by disabling file
|
||||
|
||||
@@ -19,27 +19,9 @@
|
||||
#include <test/macros.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
#include <setjmp.h>
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Static global variables */
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t expected_call;
|
||||
uint8_t expected_call_happened;
|
||||
|
||||
jmp_buf state;
|
||||
|
||||
mbedtls_test_param_failed_location_record_t location_record;
|
||||
}
|
||||
param_failed_ctx_t;
|
||||
static param_failed_ctx_t param_failed_ctx;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
static mbedtls_platform_context platform_ctx;
|
||||
#endif
|
||||
@@ -222,67 +204,6 @@ int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
void mbedtls_test_param_failed_get_location_record(
|
||||
mbedtls_test_param_failed_location_record_t *location_record )
|
||||
{
|
||||
*location_record = param_failed_ctx.location_record;
|
||||
}
|
||||
|
||||
void mbedtls_test_param_failed_expect_call( void )
|
||||
{
|
||||
param_failed_ctx.expected_call_happened = 0;
|
||||
param_failed_ctx.expected_call = 1;
|
||||
}
|
||||
|
||||
int mbedtls_test_param_failed_check_expected_call( void )
|
||||
{
|
||||
param_failed_ctx.expected_call = 0;
|
||||
|
||||
if( param_failed_ctx.expected_call_happened != 0 )
|
||||
return( 0 );
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
void* mbedtls_test_param_failed_get_state_buf( void )
|
||||
{
|
||||
return ¶m_failed_ctx.state;
|
||||
}
|
||||
|
||||
void mbedtls_test_param_failed_reset_state( void )
|
||||
{
|
||||
memset( param_failed_ctx.state, 0, sizeof( param_failed_ctx.state ) );
|
||||
}
|
||||
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line )
|
||||
{
|
||||
/* Record the location of the failure */
|
||||
param_failed_ctx.location_record.failure_condition = failure_condition;
|
||||
param_failed_ctx.location_record.file = file;
|
||||
param_failed_ctx.location_record.line = line;
|
||||
|
||||
/* If we are testing the callback function... */
|
||||
if( param_failed_ctx.expected_call != 0 )
|
||||
{
|
||||
param_failed_ctx.expected_call = 0;
|
||||
param_failed_ctx.expected_call_happened = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ...else try a long jump. If the execution state has not been set-up
|
||||
* or reset then the long jump buffer is all zero's and the call will
|
||||
* with high probability fault, emphasizing there is something to look
|
||||
* at.
|
||||
*/
|
||||
|
||||
longjmp( param_failed_ctx.state, 1 );
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
void mbedtls_test_err_add_check( int high, int low,
|
||||
const char *file, int line )
|
||||
|
||||
@@ -28,11 +28,6 @@
|
||||
#include "mbedtls/memory_buffer_alloc.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include <setjmp.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <basetsd.h>
|
||||
typedef UINT8 uint8_t;
|
||||
@@ -78,10 +73,6 @@ typedef struct data_tag
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Global variables */
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
jmp_buf jmp_tmp;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Helper flags for complex dependencies */
|
||||
|
||||
|
||||
@@ -176,26 +176,7 @@ void execute_function_ptr(TestWrapper_t fp, void **params)
|
||||
mbedtls_test_enable_insecure_external_rng( );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
mbedtls_test_param_failed_location_record_t location_record;
|
||||
|
||||
if ( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 )
|
||||
{
|
||||
fp( params );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unexpected parameter validation error */
|
||||
mbedtls_test_param_failed_get_location_record( &location_record );
|
||||
mbedtls_test_fail( location_record.failure_condition,
|
||||
location_record.line,
|
||||
location_record.file );
|
||||
}
|
||||
|
||||
mbedtls_test_param_failed_reset_state( );
|
||||
#else
|
||||
fp( params );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
mbedtls_test_mutex_usage_check( );
|
||||
|
||||
Reference in New Issue
Block a user