fix error found by coverity: check if ctx is != NULL before calling BN_CTX_end()
authorNils Larsch <nils@openssl.org>
Mon, 13 Mar 2006 23:14:57 +0000 (23:14 +0000)
committerNils Larsch <nils@openssl.org>
Mon, 13 Mar 2006 23:14:57 +0000 (23:14 +0000)
crypto/dh/dh_key.c
crypto/ec/ec2_smpl.c
crypto/ec/ec_check.c
crypto/ec/ecp_smpl.c
crypto/rsa/rsa_gen.c

index cc17c8851b691daf2798cad861f56b03adb9cbb1..79984e13bc927111d08b81ddb2b98a389f78356b 100644 (file)
@@ -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);
        }
 
index a2eb64859f2421839a599623eda50bc9cda7ef1c..527e6d81472103b9140a184f60028301d8309a3b 100644 (file)
@@ -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;
index f22c5641a8177dc8bb3317a60a424230e00a8a12..0e316b4b3ff075234fcd62791d2995442710be01 100644 (file)
@@ -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)
index 75296a36733089fb555ed2bc703a044863e4c58d..4d26f8bdf6921f4ae9a9e5be06fbde3f54b55628 100644 (file)
@@ -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;
index 383d6095f57c989522d1aa6ec860d7f8a7f10173..742f8b18e5addabe76b5f67f07845eeac0b9a89a 100644 (file)
@@ -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;
        }