提交 2bbf0baa 编写于 作者: F FdaSilvaYY 提交者: Rich Salz

Add checks on CRYPTO_new_ex_data return value...

with some adaptation to new multi-threading API.

Once reference, lock, meth and flag fields are setup,
DSA_free/DH_free can be called directly.
Reviewed-by: NRichard Levitte <levitte@openssl.org>
Reviewed-by: NRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/996)
上级 25a807bc
...@@ -109,13 +109,20 @@ DH *DH_new_method(ENGINE *engine) ...@@ -109,13 +109,20 @@ DH *DH_new_method(ENGINE *engine)
return NULL; return NULL;
} }
ret->references = 1;
ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) {
OPENSSL_free(ret);
return NULL;
}
ret->meth = DH_get_default_method(); ret->meth = DH_get_default_method();
#ifndef OPENSSL_NO_ENGINE #ifndef OPENSSL_NO_ENGINE
ret->flags = ret->meth->flags; /* early default init */
if (engine) { if (engine) {
if (!ENGINE_init(engine)) { if (!ENGINE_init(engine)) {
DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB); DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);
OPENSSL_free(ret); goto err;
return NULL;
} }
ret->engine = engine; ret->engine = engine;
} else } else
...@@ -124,29 +131,19 @@ DH *DH_new_method(ENGINE *engine) ...@@ -124,29 +131,19 @@ DH *DH_new_method(ENGINE *engine)
ret->meth = ENGINE_get_DH(ret->engine); ret->meth = ENGINE_get_DH(ret->engine);
if (ret->meth == NULL) { if (ret->meth == NULL) {
DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB); DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine); goto err;
OPENSSL_free(ret);
return NULL;
} }
} }
#endif #endif
ret->references = 1;
ret->flags = ret->meth->flags; ret->flags = ret->meth->flags;
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data); if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data))
goto err;
ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) {
#ifndef OPENSSL_NO_ENGINE
ENGINE_finish(ret->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
OPENSSL_free(ret);
return NULL;
}
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
DHerr(DH_F_DH_NEW_METHOD, ERR_R_INIT_FAIL);
err:
DH_free(ret); DH_free(ret);
ret = NULL; ret = NULL;
} }
......
...@@ -111,20 +111,27 @@ const DSA_METHOD *DSA_get_method(DSA *d) ...@@ -111,20 +111,27 @@ const DSA_METHOD *DSA_get_method(DSA *d)
DSA *DSA_new_method(ENGINE *engine) DSA *DSA_new_method(ENGINE *engine)
{ {
DSA *ret; DSA *ret = OPENSSL_zalloc(sizeof(*ret));
ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_MALLOC_FAILURE); DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
ret->references = 1;
ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) {
OPENSSL_free(ret);
return NULL;
}
ret->meth = DSA_get_default_method(); ret->meth = DSA_get_default_method();
#ifndef OPENSSL_NO_ENGINE #ifndef OPENSSL_NO_ENGINE
ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; /* early default init */
if (engine) { if (engine) {
if (!ENGINE_init(engine)) { if (!ENGINE_init(engine)) {
DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB); DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
OPENSSL_free(ret); goto err;
return NULL;
} }
ret->engine = engine; ret->engine = engine;
} else } else
...@@ -133,29 +140,19 @@ DSA *DSA_new_method(ENGINE *engine) ...@@ -133,29 +140,19 @@ DSA *DSA_new_method(ENGINE *engine)
ret->meth = ENGINE_get_DSA(ret->engine); ret->meth = ENGINE_get_DSA(ret->engine);
if (ret->meth == NULL) { if (ret->meth == NULL) {
DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB); DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine); goto err;
OPENSSL_free(ret);
return NULL;
} }
} }
#endif #endif
ret->references = 1;
ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW;
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data))
goto err;
ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) {
#ifndef OPENSSL_NO_ENGINE
ENGINE_finish(ret->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
OPENSSL_free(ret);
return NULL;
}
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_INIT_FAIL);
err:
DSA_free(ret); DSA_free(ret);
ret = NULL; ret = NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册