44#include "mbedtls/pk.h"
55#include <test/ssl_helpers.h>
66
7+ #if defined(_WIN32)
8+ # include <stdlib.h>
9+ # include <crtdbg.h>
10+ #endif
11+
712// Use a macro instead of sizeof(mbedtls_ms_time_t) because the expression store
813// doesn't exclude entries based on depends_on headers, which would cause failures
914// in builds without MBEDTLS_HAVE_TIME
@@ -55,6 +60,23 @@ static void string_debug(void *data, int level, const char *file, int line, cons
5560 buffer->ptr = p;
5661}
5762#endif /* MBEDTLS_SSL_TLS_C */
63+
64+ #if defined(_WIN32)
65+ static void noop_invalid_parameter_handler(
66+ const wchar_t *expression,
67+ const wchar_t *function,
68+ const wchar_t *file,
69+ unsigned int line,
70+ uintptr_t pReserved)
71+ {
72+ (void) expression;
73+ (void) function;
74+ (void) file;
75+ (void) line;
76+ (void) pReserved;
77+ }
78+ #endif /* _WIN32 */
79+
5880/* END_HEADER */
5981
6082/* BEGIN_DEPENDENCIES
@@ -66,6 +88,17 @@ static void string_debug(void *data, int level, const char *file, int line, cons
6688void printf_int_expr(intmax_t smuggle_format_expr, /* TODO: teach test framework about string expressions */
6789 intmax_t sizeof_x, intmax_t x, char *result)
6890{
91+ #if defined(_WIN32)
92+ /* Windows treats any invalid format specifiers passsed to the CRT as fatal assertion failures.
93+ Disable this behaviour temporarily, so the rest of the test cases can complete. */
94+ _invalid_parameter_handler saved_handler =
95+ _set_invalid_parameter_handler(noop_invalid_parameter_handler);
96+
97+ // Disable assertion pop-up window in Debug builds
98+ int saved_report_mode = _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_REPORT_MODE);
99+ _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
100+ #endif
101+
69102 const char *format = (char *) ((uintptr_t) smuggle_format_expr);
70103 char *output = NULL;
71104 const size_t n = strlen(result);
@@ -87,6 +120,13 @@ void printf_int_expr(intmax_t smuggle_format_expr, /* TODO: teach test framework
87120exit:
88121 mbedtls_free(output);
89122 output = NULL;
123+
124+ #if defined(_WIN32)
125+ // Restore default Windows behaviour
126+ _set_invalid_parameter_handler(saved_handler);
127+ _CrtSetReportMode(_CRT_ASSERT, saved_report_mode);
128+ (void) saved_report_mode;
129+ #endif
90130}
91131/* END_CASE */
92132
0 commit comments