From: Dr. Stephen Henson Date: Sat, 23 Jun 2001 23:07:34 +0000 (+0000) Subject: In {RSA,DSA,DH}_new_method(x) need to increase the reference X-Git-Tag: OpenSSL_0_9_6c~182^2~73 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0c9de428ae03a3dd9272aba90c595f6c25a4525d;p=oweals%2Fopenssl.git In {RSA,DSA,DH}_new_method(x) need to increase the reference count of the ENGINE is x is not NULL since it will be freed in {RSA,DSA,DH}_free(). --- diff --git a/crypto/dh/dh_lib.c b/crypto/dh/dh_lib.c index b3c609e8be..2d778ef300 100644 --- a/crypto/dh/dh_lib.c +++ b/crypto/dh/dh_lib.c @@ -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; diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c index 1b33705f46..48b228f3a1 100644 --- a/crypto/dsa/dsa_lib.c +++ b/crypto/dsa/dsa_lib.c @@ -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; diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c index 3a4760c8d4..315671a60e 100644 --- a/crypto/rsa/rsa_lib.c +++ b/crypto/rsa/rsa_lib.c @@ -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;