Change the use of setjmp/longjmp in parameter failure callback
Change the use of setjmp and longjmp in signalling parameter validation failures
when using the MBEDTLS_CHECK_PARAMS config.h option. This change allows
all calls which might result in a call to the parameter validation failure
handler to always be caught, even without use of the new macros, by placing a
setjmp() in the outer function which calls the test function, which the handler
can jump to.
This has several benefits:
* it allows us to remove the clang compiler warning (-Wclobbered) caused
by local auto variables being in the same function as the call to setjmp.
* removes the need to wrap all function calls in the test functions with the
TEST_ASSERT() macro. Now all parameter validation function calls should be
caught.
diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function
index 2ba919c..ca4783d 100644
--- a/tests/suites/main_test.function
+++ b/tests/suites/main_test.function
@@ -134,9 +134,39 @@
#line $line_no "suites/main_test.function"
};
+/**
+ * \brief Execute the test function.
+ *
+ * This is a wrapper function around the test function execution
+ * to allow the setjmp() call used to catch any calls to the
+ * parameter failure callback, to be used. Calls to setjmp()
+ * can invalidate the state of any local auto variables.
+ *
+ * \param fp Function pointer to the test function
+ * \param params Parameters to pass
+ *
+ */
+void execute_function_ptr(TestWrapper_t fp, void **params)
+{
+#if defined(MBEDTLS_CHECK_PARAMS)
+ if ( setjmp( param_fail_jmp ) == 0 )
+ {
+ fp( params );
+ }
+ else
+ {
+ /* Unexpected parameter validation error */
+ test_info.failed = 1;
+ }
+
+ memset( param_fail_jmp, 0, sizeof(jmp_buf) );
+#else
+ fp( params );
+#endif
+}
/**
- * \brief Dispatches test functions based on function index.
+ * \brief Dispatches test functions based on function index.
*
* \param exp_id Test function index.
*
@@ -153,7 +183,7 @@
{
fp = test_funcs[func_idx];
if ( fp )
- fp( params );
+ execute_function_ptr(fp, params);
else
ret = DISPATCH_UNSUPPORTED_SUITE;
}