Pointer to BN_MONT_CTX could be used uninitialized.
[openssl.git] / crypto / dh / dh_key.c
index 1439a7a9e96dfd6d97230b03df747e36a879a725..9148f179f7d725404a4bc6c85a75c7dfa9fe43bd 100644 (file)
@@ -104,7 +104,7 @@ static int generate_key(DH *dh)
        int generate_new_key=0;
        unsigned l;
        BN_CTX *ctx;
-       BN_MONT_CTX *mont;
+       BN_MONT_CTX *mont=NULL;
        BIGNUM *pub_key=NULL,*priv_key=NULL;
 
        ctx = BN_CTX_new();
@@ -130,8 +130,7 @@ static int generate_key(DH *dh)
 
        if (dh->flags & DH_FLAG_CACHE_MONT_P)
                {
-               mont = BN_MONT_CTX_set_locked(
-                               (BN_MONT_CTX **)&dh->method_mont_p,
+               mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,
                                CRYPTO_LOCK_DH, dh->p, ctx);
                if (!mont)
                        goto err;
@@ -161,7 +160,7 @@ err:
 static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
        {
        BN_CTX *ctx;
-       BN_MONT_CTX *mont;
+       BN_MONT_CTX *mont=NULL;
        BIGNUM *tmp;
        int ret= -1;
 
@@ -178,8 +177,7 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
 
        if (dh->flags & DH_FLAG_CACHE_MONT_P)
                {
-               mont = BN_MONT_CTX_set_locked(
-                               (BN_MONT_CTX **)&dh->method_mont_p,
+               mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,
                                CRYPTO_LOCK_DH, dh->p, ctx);
                if (!mont)
                        goto err;
@@ -222,6 +220,6 @@ static int dh_init(DH *dh)
 static int dh_finish(DH *dh)
        {
        if(dh->method_mont_p)
-               BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
+               BN_MONT_CTX_free(dh->method_mont_p);
        return(1);
        }