Fix |BN_CTX_get| error checking in |BN_from_montgomery|.

In the case |BN_CTX_get| failed, the function returned without calling
|BN_CTX_end|. Fix that.

Change-Id: Ia24cba3256e2cec106b539324e9679d690048780
Reviewed-on: https://boringssl-review.googlesource.com/7592
Reviewed-by: David Benjamin <davidben@google.com>
This commit is contained in:
Brian Smith 2016-03-25 18:12:13 -10:00 committed by David Benjamin
parent 9d354693ff
commit 44477c03b9

View File

@ -410,23 +410,24 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r,
return 1; return 1;
} }
int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, const BN_MONT_CTX *mont, int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, const BN_MONT_CTX *mont,
BN_CTX *ctx) { BN_CTX *ctx) {
int retn = 0; int ret = 0;
BIGNUM *t; BIGNUM *t;
BN_CTX_start(ctx); BN_CTX_start(ctx);
t = BN_CTX_get(ctx); t = BN_CTX_get(ctx);
if (t == NULL) { if (t == NULL ||
return 0; !BN_copy(t, a)) {
goto err;
} }
if (BN_copy(t, a)) { ret = BN_from_montgomery_word(r, t, mont);
retn = BN_from_montgomery_word(ret, t, mont);
} err:
BN_CTX_end(ctx); BN_CTX_end(ctx);
return retn; return ret;
} }
int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,