Skip to content

Commit

Permalink
Move MPI initialization to start of function
Browse files Browse the repository at this point in the history
This prevents a call to mbedtls_mpi_free() on uninitialized data when
USE_PSA_INIT() fails.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
  • Loading branch information
davidhorstmann-arm committed Dec 8, 2023
1 parent 0dc3ed0 commit ec4c47f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/suites/test_suite_x509write.function
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,11 @@ void x509_set_serial_check()
mbedtls_mpi serial_mpi;
uint8_t invalid_serial[MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN + 1];

mbedtls_mpi_init(&serial_mpi);

USE_PSA_INIT();
memset(invalid_serial, 0x01, sizeof(invalid_serial));

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),
Expand Down

0 comments on commit ec4c47f

Please sign in to comment.