diff options
author | Rich Salz <rsalz@openssl.org> | 2018-03-27 16:25:08 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2018-03-27 16:25:08 -0400 |
commit | e6e9170d6e28038768895e1af18e3aad8093bf4b (patch) | |
tree | 62f594f0968ff8d6c27795377a102e4aab373b00 /crypto/bn | |
parent | 98c03302fb7b855647aa14022f61f5fb272e514a (diff) |
Allow NULL for some _free routines.
Based on the description in https://github.com/openssl/openssl/pull/5757,
this re-implements the "allow NULL to be passed" behavior of a number of
xxx_free routines. I also fixed up some egregious formatting errors
that were nearby.
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5761)
Diffstat (limited to 'crypto/bn')
-rw-r--r-- | crypto/bn/bn_blind.c | 2 | ||||
-rw-r--r-- | crypto/bn/bn_ctx.c | 2 | ||||
-rw-r--r-- | crypto/bn/bn_mont.c | 14 | ||||
-rw-r--r-- | crypto/bn/bn_recp.c | 6 |
4 files changed, 16 insertions, 8 deletions
diff --git a/crypto/bn/bn_blind.c b/crypto/bn/bn_blind.c index 8bd61567e7..985d3ef32b 100644 --- a/crypto/bn/bn_blind.c +++ b/crypto/bn/bn_blind.c @@ -80,6 +80,8 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod) void BN_BLINDING_free(BN_BLINDING *r) { + if (r == NULL) + return; BN_free(r->A); BN_free(r->Ai); BN_free(r->e); diff --git a/crypto/bn/bn_ctx.c b/crypto/bn/bn_ctx.c index 7202aef326..68c0468743 100644 --- a/crypto/bn/bn_ctx.c +++ b/crypto/bn/bn_ctx.c @@ -156,6 +156,8 @@ BN_CTX *BN_CTX_secure_new(void) void BN_CTX_free(BN_CTX *ctx) { + if (ctx == NULL) + return; #ifdef BN_CTX_DEBUG { BN_POOL_ITEM *pool = ctx->pool.head; diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c index bae7d235bd..c882891d5e 100644 --- a/crypto/bn/bn_mont.c +++ b/crypto/bn/bn_mont.c @@ -208,18 +208,20 @@ BN_MONT_CTX *BN_MONT_CTX_new(void) void BN_MONT_CTX_init(BN_MONT_CTX *ctx) { ctx->ri = 0; - bn_init(&(ctx->RR)); - bn_init(&(ctx->N)); - bn_init(&(ctx->Ni)); + bn_init(&ctx->RR); + bn_init(&ctx->N); + bn_init(&ctx->Ni); ctx->n0[0] = ctx->n0[1] = 0; ctx->flags = 0; } void BN_MONT_CTX_free(BN_MONT_CTX *mont) { - BN_clear_free(&(mont->RR)); - BN_clear_free(&(mont->N)); - BN_clear_free(&(mont->Ni)); + if (mont == NULL) + return; + BN_clear_free(&mont->RR); + BN_clear_free(&mont->N); + BN_clear_free(&mont->Ni); if (mont->flags & BN_FLG_MALLOCED) OPENSSL_free(mont); } diff --git a/crypto/bn/bn_recp.c b/crypto/bn/bn_recp.c index 923a9b33d8..8eb500b61a 100644 --- a/crypto/bn/bn_recp.c +++ b/crypto/bn/bn_recp.c @@ -32,8 +32,10 @@ BN_RECP_CTX *BN_RECP_CTX_new(void) void BN_RECP_CTX_free(BN_RECP_CTX *recp) { - BN_free(&(recp->N)); - BN_free(&(recp->Nr)); + if (recp == NULL) + return; + BN_free(&recp->N); + BN_free(&recp->Nr); if (recp->flags & BN_FLG_MALLOCED) OPENSSL_free(recp); } |