Fix MD_PSA_INIT called before initializing some data structures
This fixes accesses to uninitialized memory in test code if
`psa_crypto_init()` fails.
A lot of those were pointed out by Coverity. I quickly reviewed all calls to
`MD_PSA_INIT()` manually, rather than follow any particular list.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/suites/test_suite_pem.function b/tests/suites/test_suite_pem.function
index 413dc55..091cbd1 100644
--- a/tests/suites/test_suite_pem.function
+++ b/tests/suites/test_suite_pem.function
@@ -66,6 +66,7 @@
char *pwd, int res, data_t *out)
{
mbedtls_pem_context ctx;
+ mbedtls_pem_init(&ctx);
int ret;
size_t use_len = 0;
size_t pwd_len = strlen(pwd);
@@ -73,8 +74,6 @@
MD_PSA_INIT();
- mbedtls_pem_init(&ctx);
-
ret = mbedtls_pem_read_buffer(&ctx, header, footer, (unsigned char *) data,
(unsigned char *) pwd, pwd_len, &use_len);
TEST_ASSERT(ret == res);