Add handlers for parameter validation in the sample programs

The sample programs require an additional handler function of
mbedtls_param_failed() to handle any failed parameter validation checks enabled
by the MBEDTLS_CHECK_PARAMS config.h option.
This commit is contained in:
Simon Butcher 2018-12-06 17:43:31 +00:00 committed by Manuel Pégourié-Gonnard
parent a646345e3f
commit 63cb97e562
37 changed files with 312 additions and 0 deletions

View File

@ -78,6 +78,16 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %s\n", file, line,
failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
int ret = 0;
@ -109,6 +119,7 @@ int main( int argc, char *argv[] )
off_t filesize, offset;
#endif
mbedtls_aes_init( NULL );
mbedtls_aes_init( &aes_ctx );
mbedtls_md_init( &sha_ctx );

View File

@ -80,6 +80,16 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %s\n", file, line,
failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
int ret = 1, i, n;

View File

@ -70,6 +70,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( void )
{
FILE *f;

View File

@ -68,6 +68,14 @@ int main( void )
*/
#define GENERATOR "4"
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char **argv )
{
int ret = 1;

View File

@ -70,6 +70,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( void )
{
FILE *f;

View File

@ -52,6 +52,14 @@ int main( void )
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/ecdh.h"
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
int ret = 1;

View File

@ -99,6 +99,14 @@ static void dump_pubkey( const char *title, mbedtls_ecdsa_context *key )
#define dump_pubkey( a, b )
#endif
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
int ret = 1;

View File

@ -135,6 +135,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -73,6 +73,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -96,6 +96,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -59,6 +59,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -59,6 +59,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -59,6 +59,14 @@ int main( void )
#include <stdio.h>
#include <string.h>
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -55,6 +55,14 @@ int main( void )
#include <stdio.h>
#include <string.h>
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -58,6 +58,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -58,6 +58,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -62,6 +62,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( void )
{
int ret = 1;

View File

@ -60,6 +60,14 @@ int main( void )
#include <stdio.h>
#include <string.h>
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -59,6 +59,14 @@ int main( void )
#include <stdio.h>
#include <string.h>
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -52,6 +52,15 @@ int main( void )
return( 0 );
}
#else
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
FILE *f;

View File

@ -79,6 +79,14 @@ int main( void )
#define DEBUG_LEVEL 0
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )

View File

@ -88,6 +88,14 @@ int main( void )
#define READ_TIMEOUT_MS 10000 /* 5 seconds */
#define DEBUG_LEVEL 0
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )

View File

@ -168,6 +168,14 @@ enum exit_codes
ssl_write_failed,
};
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( void )
{
int ret = exit_ok;

View File

@ -70,6 +70,14 @@ int main( void )
#define DEBUG_LEVEL 1
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )

View File

@ -314,6 +314,14 @@ int main( void )
#define ALPN_LIST_SIZE 10
#define CURVE_LIST_SIZE 20
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -86,6 +86,14 @@ int main( void )
#define DEBUG_LEVEL 0
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )

View File

@ -141,6 +141,14 @@ int main( void )
" force_ciphersuite=<name> default: all enabled\n"\
" acceptable ciphersuite names:\n"
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -80,6 +80,14 @@ int main( void )
#define DEBUG_LEVEL 0
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )

View File

@ -426,6 +426,14 @@ int main( void )
(out_be)[(i) + 7] = (unsigned char)( ( (in_le) >> 0 ) & 0xFF ); \
}
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -254,6 +254,14 @@ typedef struct {
rsa, dhm, ecdsa, ecdh;
} todo_list;
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( int argc, char *argv[] )
{
int i;

View File

@ -77,6 +77,14 @@
#include "mbedtls/memory_buffer_alloc.h"
#endif
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
{
int ret;

View File

@ -81,6 +81,14 @@ const char *client_private_keys[MAX_CLIENT_CERTS] =
"cert_digest.key"
};
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
int main( void )
{
int ret = 1, i;

View File

@ -99,6 +99,14 @@ int main( void )
" permissive=%%d default: 0 (disabled)\n" \
"\n"
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -100,6 +100,14 @@ int main( void )
" SHA384, SHA512\n" \
"\n"
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -153,6 +153,14 @@ int main( void )
" object_signing_ca\n" \
"\n"
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -60,6 +60,14 @@ int main( void )
" filename=%%s default: crl.pem\n" \
"\n"
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/

View File

@ -60,6 +60,14 @@ int main( void )
" filename=%%s default: cert.req\n" \
"\n"
#if defined( MBEDTLS_CHECK_PARAMS ) && defined(MBEDTLS_PLATFORM_C)
void mbedtls_param_failed( char* failure_condition, char* file, int line )
{
mbedtls_printf("%s:%i: Input param failed - %sn", file, line, failure_condition );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
#endif
/*
* global options
*/