bignum: fix memory leak in GCD with 0 as an input
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
diff --git a/library/bignum.c b/library/bignum.c
index 96cade4..3587148 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -1841,10 +1841,12 @@
/* Handle special cases (that don't happen in crypto usage) */
if (mbedtls_mpi_core_check_zero_ct(TA.p, TA.n) == MBEDTLS_CT_FALSE) {
- return mbedtls_mpi_copy(G, &TB); // GCD(0, B) = abs(B)
+ MBEDTLS_MPI_CHK(mbedtls_mpi_copy(G, &TB)); // GCD(0, B) = abs(B)
+ goto cleanup;
}
if (mbedtls_mpi_core_check_zero_ct(TB.p, TB.n) == MBEDTLS_CT_FALSE) {
- return mbedtls_mpi_copy(G, &TA); // GCD(A, 0) = abs(A)
+ MBEDTLS_MPI_CHK(mbedtls_mpi_copy(G, &TA)); // GCD(A, 0) = abs(A)
+ goto cleanup;
}
const size_t za = mbedtls_mpi_lsb(&TA);