From e04a97a1eb3586e2cafb74fb744cc5b3205b5539 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 8 Dec 2023 18:27:48 +0000 Subject: [PATCH] Move MPI initialization to start of function This prevents a call to mbedtls_mpi_free() on uninitialized data when USE_PSA_INIT() fails. Signed-off-by: David Horstmann --- tests/suites/test_suite_x509write.function | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/suites/test_suite_x509write.function b/tests/suites/test_suite_x509write.function index 4de9addca..b59fd48f3 100644 --- a/tests/suites/test_suite_x509write.function +++ b/tests/suites/test_suite_x509write.function @@ -665,13 +665,15 @@ void x509_set_serial_check() mbedtls_x509write_cert ctx; uint8_t invalid_serial[MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN + 1]; +#if defined(MBEDTLS_TEST_DEPRECATED) && defined(MBEDTLS_BIGNUM_C) + mbedtls_mpi serial_mpi; + mbedtls_mpi_init(&serial_mpi); +#endif + USE_PSA_INIT(); memset(invalid_serial, 0x01, sizeof(invalid_serial)); #if defined(MBEDTLS_TEST_DEPRECATED) && defined(MBEDTLS_BIGNUM_C) - mbedtls_mpi serial_mpi; - - mbedtls_mpi_init(&serial_mpi); TEST_EQUAL(mbedtls_mpi_read_binary(&serial_mpi, invalid_serial, sizeof(invalid_serial)), 0); TEST_EQUAL(mbedtls_x509write_crt_set_serial(&ctx, &serial_mpi),