Skip to content

Commit

Permalink
Fix memory leak in mbedtls_mpi_sub_abs
Browse files Browse the repository at this point in the history
Fix a memory leak in mbedtls_mpi_sub_abs when the output parameter is
aliased to the second operand (X = A - X) and the result is negative.

Signed-off-by: Gilles Peskine <[email protected]>
  • Loading branch information
gilles-peskine-arm committed Jul 22, 2020
1 parent 2845fcc commit 84697ca
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,10 @@ int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
/* If we ran out of space for the carry, it means that the result
* is negative. */
if( n == X->n )
return( MBEDTLS_ERR_MPI_NEGATIVE_VALUE );
{
ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
goto cleanup;
}
--X->p[n];
}

Expand Down

0 comments on commit 84697ca

Please sign in to comment.