From 45b6e5e69f582bafa3478e3c5d7da9880e1f236a Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 12 Sep 2023 11:29:16 +0100 Subject: [PATCH] Prevent potential use of uninitialised data in pkcs7 tests Move the initialisation of the pkcs7 object to before the first possible test failure, otherwise failure in those tests could result in an uninitialised pointer being free'd. Found by coverity. Signed-off-by: Paul Elliott --- tests/suites/test_suite_pkcs7.function | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/suites/test_suite_pkcs7.function b/tests/suites/test_suite_pkcs7.function index a0da1d72d9..65384a8550 100644 --- a/tests/suites/test_suite_pkcs7.function +++ b/tests/suites/test_suite_pkcs7.function @@ -78,6 +78,8 @@ void pkcs7_verify(char *pkcs7_file, MD_OR_USE_PSA_INIT(); + mbedtls_pkcs7_init(&pkcs7); + /* crt_files are space seprated list */ for (i = 0; i < strlen(crt_files); i++) { if (crt_files[i] == ' ') { @@ -100,7 +102,6 @@ void pkcs7_verify(char *pkcs7_file, i = k; } - mbedtls_pkcs7_init(&pkcs7); for (i = 0; i < n_crts; i++) { TEST_CALLOC(crts[i], 1); mbedtls_x509_crt_init(crts[i]);