From b12dd550fd6af687ef95c584d0d8366c34965cc8 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 10 Feb 2016 17:35:43 +0900 Subject: ecc: Fix memory leaks on error. * cipher/ecc.c (ecc_decrypt_raw): Go to leave to release memory. * mpi/ec.c (_gcry_mpi_ec_curve_point): Likewise. -- Signed-off-by: NIIBE Yutaka --- cipher/ecc.c | 4 ++-- mpi/ec.c | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cipher/ecc.c b/cipher/ecc.c index b861925b..d1fe8237 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -1572,8 +1572,8 @@ ecc_decrypt_raw (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t keyparms) if (!_gcry_mpi_ec_curve_point (&kG, ec)) { - point_free (&kG); - return GPG_ERR_INV_DATA; + rc = GPG_ERR_INV_DATA; + goto leave; } /* R = dkG */ diff --git a/mpi/ec.c b/mpi/ec.c index 346e5f1e..f0b83743 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -1478,10 +1478,12 @@ _gcry_mpi_ec_curve_point (gcry_mpi_point_t point, mpi_ec_t ctx) { case MPI_EC_WEIERSTRASS: { - gcry_mpi_t xxx = mpi_new (0); + gcry_mpi_t xxx; if (_gcry_mpi_ec_get_affine (x, y, point, ctx)) - return 0; + goto leave; + + xxx = mpi_new (0); /* y^2 == x^3 + a·x + b */ ec_pow2 (y, y, ctx); @@ -1502,7 +1504,7 @@ _gcry_mpi_ec_curve_point (gcry_mpi_point_t point, mpi_ec_t ctx) #define xx y /* With Montgomery curve, only X-coordinate is valid. */ if (_gcry_mpi_ec_get_affine (x, NULL, point, ctx)) - return 0; + goto leave; /* The equation is: b * y^2 == x^3 + a · x^2 + x */ /* We check if right hand is quadratic residue or not by @@ -1530,7 +1532,7 @@ _gcry_mpi_ec_curve_point (gcry_mpi_point_t point, mpi_ec_t ctx) case MPI_EC_EDWARDS: { if (_gcry_mpi_ec_get_affine (x, y, point, ctx)) - return 0; + goto leave; /* a · x^2 + y^2 - 1 - b · x^2 · y^2 == 0 */ ec_pow2 (x, x, ctx); @@ -1553,6 +1555,7 @@ _gcry_mpi_ec_curve_point (gcry_mpi_point_t point, mpi_ec_t ctx) break; } + leave: _gcry_mpi_release (w); _gcry_mpi_release (x); _gcry_mpi_release (y); -- cgit v1.2.1