From b2aa938ed6e78087d561569b5af5ea92244c7861 Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Thu, 17 Jan 2019 13:30:57 +0100 Subject: [PATCH 1/2] fix memory leak in mpi_miller_rabin() Fixes memory leak in mpi_miller_rabin() that occurs when the function has failed to obtain a usable random 'A' 30 turns in a row. Signed-off-by: Jens Wiklander --- library/bignum.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/bignum.c b/library/bignum.c index ba817bebf..529b937dc 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -2128,7 +2128,8 @@ static int mpi_miller_rabin( const mbedtls_mpi *X, size_t rounds, } if (count++ > 30) { - return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; + ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; + goto cleanup; } } while ( mbedtls_mpi_cmp_mpi( &A, &W ) >= 0 || From 4073b794c5ce1b05f07f99b1bc54a585049995d2 Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Thu, 17 Jan 2019 17:45:05 +0100 Subject: [PATCH 2/2] Add ChangeLog entry Signed-off-by: Jens Wiklander --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 07cc87692..d26b9cd8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,8 @@ Bugfix * Remove a duplicate #include in a sample program. Fixed by Masashi Honma #2326. * Reduce stack usage of `mpi_write_hlp()` by eliminating recursion. Fixes #2190. + * Fix memory leak in in mpi_miller_rabin(). Contributed by + Jens Wiklander in #2363. Changes * Include configuration file in all header files that use configuration,