X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Finit.c;h=c7eff8ba4ab51c88c736ac3d6e1d6e9739d8acaa;hp=f01bd4d93f6e11740263a270ca54a489a1303edd;hb=c7b7938e75587d1ff8cf28c9de966623cfbe8858;hpb=0fc32b0718ec210e03b6d8623d4819ed04615a1b diff --git a/crypto/init.c b/crypto/init.c index f01bd4d93f..c7eff8ba4a 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -57,6 +57,7 @@ #include #include +#include #include #include #include @@ -253,6 +254,7 @@ static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc) #endif +typedef struct ossl_init_stop_st OPENSSL_INIT_STOP; struct ossl_init_stop_st { void (*handler)(void); OPENSSL_INIT_STOP *next; @@ -268,7 +270,9 @@ static void ossl_init_base(void) fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n"); #endif ossl_init_setup_thread_stop(); +#ifndef OPENSSL_SYS_UEFI atexit(OPENSSL_cleanup); +#endif OPENSSL_cpuid_setup(); base_inited = 1; } @@ -606,21 +610,6 @@ void OPENSSL_cleanup(void) base_inited = 0; } -static const OPENSSL_INIT_SETTINGS *ossl_init_get_setting( - const OPENSSL_INIT_SETTINGS *settings, int name) -{ - if (settings == NULL) - return NULL; - - while (settings->name != OPENSSL_INIT_SET_END) { - if (settings->name == name) - return settings; - settings++; - } - - return NULL; -} - /* * If this function is called with a non NULL settings value then it must be * called prior to any threads making calls to any OpenSSL functions, @@ -628,8 +617,20 @@ static const OPENSSL_INIT_SETTINGS *ossl_init_get_setting( */ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) { - if (stopped) + static int stoperrset = 0; + + if (stopped) { + if (!stoperrset) { + /* + * We only ever set this once to avoid getting into an infinite + * loop where the error system keeps trying to init and fails so + * sets an error etc + */ + stoperrset = 1; + CRYPTOerr(CRYPTO_F_OPENSSL_INIT_CRYPTO, ERR_R_INIT_FAIL); + } return 0; + } ossl_init_once_run(&base, ossl_init_base); @@ -658,14 +659,7 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) if (opts & OPENSSL_INIT_LOAD_CONFIG) { CRYPTO_w_lock(CRYPTO_LOCK_INIT); - if (settings != NULL) { - const OPENSSL_INIT_SETTINGS *curr; - curr = ossl_init_get_setting(settings, - OPENSSL_INIT_SET_CONF_FILENAME); - config_filename = (curr == NULL) ? NULL : curr->value.type_string; - } else { - config_filename = NULL; - } + config_filename = (settings == NULL) ? NULL : settings->config_name; ossl_init_once_run(&config, ossl_init_config); CRYPTO_w_unlock(CRYPTO_LOCK_INIT); }