Improve safety of a test helper

In case parsing fails and we free the pointer, we should also set it to
NULL. Otherwise, we get a double-free when the caller tries to free it
as well.

This can only happen with bad test data, but it tripped me up during
development. (I got bad test data because bignum_common.invmod()
sometimes returned a negative value, which was a surprise to me, see
previous commit.)

Signed-off-by: Manuel Pégourié-Gonnard <[email protected]>
This commit is contained in:
Manuel Pégourié-Gonnard
2025-07-28 23:43:45 +02:00
parent b3575b30f2
commit 319641a7ee
+1
View File
@@ -71,6 +71,7 @@ int mbedtls_test_read_mpi_core(mbedtls_mpi_uint **pX, size_t *plimbs,
exit:
mbedtls_free(*pX);
*pX = NULL;
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
}