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.
diff --git a/programs/ssl/dtls_client.c b/programs/ssl/dtls_client.c
index c29ab34..4d7177f 100644
--- a/programs/ssl/dtls_client.c
+++ b/programs/ssl/dtls_client.c
@@ -79,6 +79,14 @@
#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 )
diff --git a/programs/ssl/dtls_server.c b/programs/ssl/dtls_server.c
index b4ad6b5..0cee834 100644
--- a/programs/ssl/dtls_server.c
+++ b/programs/ssl/dtls_server.c
@@ -88,6 +88,14 @@
#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 )
diff --git a/programs/ssl/mini_client.c b/programs/ssl/mini_client.c
index 290455e..c447947 100644
--- a/programs/ssl/mini_client.c
+++ b/programs/ssl/mini_client.c
@@ -168,6 +168,14 @@
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;
diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c
index bf7c013..a7e4513 100644
--- a/programs/ssl/ssl_client1.c
+++ b/programs/ssl/ssl_client1.c
@@ -70,6 +70,14 @@
#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 )
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 15c778d..098c138 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -314,6 +314,14 @@
#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
*/
diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c
index 1c3a806..3304b6b 100644
--- a/programs/ssl/ssl_fork_server.c
+++ b/programs/ssl/ssl_fork_server.c
@@ -86,6 +86,14 @@
#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 )
diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c
index 16cedfe..6bf6cde 100644
--- a/programs/ssl/ssl_mail_client.c
+++ b/programs/ssl/ssl_mail_client.c
@@ -141,6 +141,14 @@
" 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
*/
diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c
index dcdafbb..044193d 100644
--- a/programs/ssl/ssl_server.c
+++ b/programs/ssl/ssl_server.c
@@ -80,6 +80,14 @@
#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 )
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index efda65d..fffd98c 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -426,6 +426,14 @@
(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
*/