In {RSA,DSA,DH}_new_method(x) need to increase the reference
authorDr. Stephen Henson <steve@openssl.org>
Sat, 23 Jun 2001 23:07:34 +0000 (23:07 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 23 Jun 2001 23:07:34 +0000 (23:07 +0000)
count of the ENGINE is x is not NULL since it will be freed
in {RSA,DSA,DH}_free().

crypto/dh/dh_lib.c
crypto/dsa/dsa_lib.c
crypto/rsa/rsa_lib.c

index b3c609e..2d778ef 100644 (file)
@@ -142,16 +142,21 @@ DH *DH_new_method(ENGINE *engine)
                DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE);
                return(NULL);
                }
-       if(engine)
-               ret->engine = engine;
+
+       if (engine)
+               {
+               if(ENGINE_init(engine))
+                       ret->engine = engine;
+               else 
+                       ret->engine = NULL;
+               }
        else
+               ret->engine=ENGINE_get_default_DH();
+       if(ret->engine == NULL)
                {
-               if((ret->engine=ENGINE_get_default_DH()) == NULL)
-                       {
-                       DHerr(DH_F_DH_NEW,ERR_LIB_ENGINE);
-                       OPENSSL_free(ret);
-                       return NULL;
-                       }
+               DHerr(DH_F_DH_NEW,ERR_LIB_ENGINE);
+               OPENSSL_free(ret);
+               return NULL;
                }
        meth = ENGINE_get_DH(ret->engine);
        ret->pad=0;
index 1b33705..48b228f 100644 (file)
@@ -146,17 +146,24 @@ DSA *DSA_new_method(ENGINE *engine)
                DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE);
                return(NULL);
                }
-       if(engine)
-               ret->engine = engine;
+
+       if (engine)
+               {
+               if(ENGINE_init(engine))
+                       ret->engine = engine;
+               else 
+                       ret->engine = NULL;
+               }
        else
+               ret->engine=ENGINE_get_default_DSA();
+
+       if(ret->engine == NULL)
                {
-               if((ret->engine=ENGINE_get_default_DSA()) == NULL)
-                       {
-                       DSAerr(DSA_F_DSA_NEW,ERR_LIB_ENGINE);
-                       OPENSSL_free(ret);
-                       return NULL;
-                       }
+               DSAerr(DSA_F_DSA_NEW,ERR_LIB_ENGINE);
+               OPENSSL_free(ret);
+               return NULL;
                }
+
        meth = ENGINE_get_DSA(ret->engine);
        ret->pad=0;
        ret->version=0;
index 3a4760c..315671a 100644 (file)
@@ -162,17 +162,23 @@ RSA *RSA_new_method(ENGINE *engine)
                return(NULL);
                }
 
-       if (engine == NULL)
+       if (engine)
                {
-               if((ret->engine=ENGINE_get_default_RSA()) == NULL)
-                       {
-                       RSAerr(RSA_F_RSA_NEW_METHOD,ERR_LIB_ENGINE);
-                       OPENSSL_free(ret);
-                       return NULL;
-                       }
+               if(ENGINE_init(engine))
+                       ret->engine = engine;
+               else 
+                       ret->engine = NULL;
                }
        else
-               ret->engine=engine;
+               ret->engine=ENGINE_get_default_RSA();
+
+       if(ret->engine == NULL)
+               {
+               RSAerr(RSA_F_RSA_NEW_METHOD,ERR_LIB_ENGINE);
+               OPENSSL_free(ret);
+               return NULL;
+               }
+
        meth = ENGINE_get_RSA(ret->engine);
 
        ret->pad=0;