diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2018-04-03 23:47:10 +0200 |
---|---|---|
committer | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2018-04-04 14:50:50 +0200 |
commit | 6b49b30811f4afa0340342af9400b8d0357b5291 (patch) | |
tree | 063c1c45e786514b7aeec7f87d012ce0776fcc56 /crypto/err | |
parent | 284f4f6b70998b2b46dc74c3003c82cb1db0e742 (diff) |
Prevent a possible recursion in ERR_get_state and fix the problem that
was pointed out in commit aef84bb4efbddfd95d042f3f5f1d362ed7d4faeb
differently.
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5863)
Diffstat (limited to 'crypto/err')
-rw-r--r-- | crypto/err/err.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/crypto/err/err.c b/crypto/err/err.c index 1fb71e745f..f55655c6b6 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -667,25 +667,23 @@ ERR_STATE *ERR_get_state(void) if (!RUN_ONCE(&err_init, err_do_init)) return NULL; - /* - * If base OPENSSL_init_crypto() hasn't been called yet, be sure to call - * it now to avoid state to be doubly allocated and thereby leak memory. - * Needed on any platform that doesn't define OPENSSL_USE_NODELETE. - */ - if (!OPENSSL_init_crypto(0, NULL)) - return NULL; - state = CRYPTO_THREAD_get_local(&err_thread_local); + if (state == (ERR_STATE*)-1) + return NULL; if (state == NULL) { + if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1)) + return NULL; + if ((state = OPENSSL_zalloc(sizeof(*state))) == NULL) { - /* ERRerr(ERR_F_ERR_GET_STATE, ERR_R_MALLOC_FAILURE); */ + CRYPTO_THREAD_set_local(&err_thread_local, NULL); return NULL; } if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE) - || !CRYPTO_THREAD_set_local(&err_thread_local, state)) { + || !CRYPTO_THREAD_set_local(&err_thread_local, state)) { ERR_STATE_free(state); + CRYPTO_THREAD_set_local(&err_thread_local, NULL); return NULL; } |