From b7a80146f45dc47ee2a7e33298d1fa4c7110cca4 Mon Sep 17 00:00:00 2001 From: Nils Larsch Date: Mon, 13 Mar 2006 23:12:08 +0000 Subject: [PATCH 1/1] fix error found by coverity: check if ctx is != NULL before calling BN_CTX_end() --- crypto/dh/dh_key.c | 7 +++++-- crypto/ec/ec2_smpl.c | 3 ++- crypto/ec/ec_check.c | 3 ++- crypto/ec/ecp_smpl.c | 3 ++- crypto/rsa/rsa_gen.c | 7 +++++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index cc17c8851b..79984e13bc 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -217,8 +217,11 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) ret=BN_bn2bin(tmp,key); err: - BN_CTX_end(ctx); - BN_CTX_free(ctx); + if (ctx != NULL) + { + BN_CTX_end(ctx); + BN_CTX_free(ctx); + } return(ret); } diff --git a/crypto/ec/ec2_smpl.c b/crypto/ec/ec2_smpl.c index a9f7c9d378..5cd1eac41f 100644 --- a/crypto/ec/ec2_smpl.c +++ b/crypto/ec/ec2_smpl.c @@ -281,7 +281,8 @@ int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) ret = 1; err: - BN_CTX_end(ctx); + if (ctx != NULL) + BN_CTX_end(ctx); if (new_ctx != NULL) BN_CTX_free(new_ctx); return ret; diff --git a/crypto/ec/ec_check.c b/crypto/ec/ec_check.c index f22c5641a8..0e316b4b3f 100644 --- a/crypto/ec/ec_check.c +++ b/crypto/ec/ec_check.c @@ -113,7 +113,8 @@ int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx) ret = 1; err: - BN_CTX_end(ctx); + if (ctx != NULL) + BN_CTX_end(ctx); if (new_ctx != NULL) BN_CTX_free(new_ctx); if (point) diff --git a/crypto/ec/ecp_smpl.c b/crypto/ec/ecp_smpl.c index 75296a3673..4d26f8bdf6 100644 --- a/crypto/ec/ecp_smpl.c +++ b/crypto/ec/ecp_smpl.c @@ -336,7 +336,8 @@ int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) ret = 1; err: - BN_CTX_end(ctx); + if (ctx != NULL) + BN_CTX_end(ctx); if (new_ctx != NULL) BN_CTX_free(new_ctx); return ret; diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c index 383d6095f5..742f8b18e5 100644 --- a/crypto/rsa/rsa_gen.c +++ b/crypto/rsa/rsa_gen.c @@ -183,8 +183,11 @@ err: RSAerr(RSA_F_RSA_BUILTIN_KEYGEN,ERR_LIB_BN); ok=0; } - BN_CTX_end(ctx); - BN_CTX_free(ctx); + if (ctx != NULL) + { + BN_CTX_end(ctx); + BN_CTX_free(ctx); + } return ok; } -- 2.34.1