[openssl-commits] [openssl] master update
Richard Levitte
levitte at openssl.org
Tue Jul 19 21:50:01 UTC 2016
The branch master has been updated
via 0a5228543cc9535b6a20d496df2c7894a4446ad0 (commit)
via c1c26660df15fe89914e1fb353dd3064f8176fb5 (commit)
via 963f043d04206ae9e4d484eee37a3ebd5a3aa701 (commit)
via c2e4e5d248567d4eea5bf6d525bdbcc09099ba6e (commit)
via 925d17f3ee4b7f7881fa77a31524ecd9f1305242 (commit)
from aebb9aac486fe81fd2bd9eca7c508d305af2fbe0 (commit)
- Log -----------------------------------------------------------------
commit 0a5228543cc9535b6a20d496df2c7894a4446ad0
Author: Richard Levitte <levitte at openssl.org>
Date: Tue Jul 19 21:48:52 2016 +0200
Document the slight change in CRYPTO_mem_ctrl()
Reviewed-by: Kurt Roeckx <kurt at openssl.org>
commit c1c26660df15fe89914e1fb353dd3064f8176fb5
Author: Richard Levitte <levitte at openssl.org>
Date: Tue Jul 19 21:33:02 2016 +0200
Document the slight change in ERR_get_next_error_library()
Reviewed-by: Kurt Roeckx <kurt at openssl.org>
commit 963f043d04206ae9e4d484eee37a3ebd5a3aa701
Author: Richard Levitte <levitte at openssl.org>
Date: Tue Jul 19 21:01:11 2016 +0200
make update
Reviewed-by: Kurt Roeckx <kurt at openssl.org>
commit c2e4e5d248567d4eea5bf6d525bdbcc09099ba6e
Author: Richard Levitte <levitte at openssl.org>
Date: Tue Jul 19 19:42:11 2016 +0200
Change all our uses of CRYPTO_THREAD_run_once to use RUN_ONCE instead
That way, we have a way to check if the init function was successful
or not.
Reviewed-by: Kurt Roeckx <kurt at openssl.org>
commit 925d17f3ee4b7f7881fa77a31524ecd9f1305242
Author: Richard Levitte <levitte at openssl.org>
Date: Tue Jul 19 19:38:57 2016 +0200
Define a few internal macros for easy use of run_once functions
Because pthread_once() takes a function taking no argument and
returning nothing, and we want to be able to check if they're
successful, we define a few internal macros to get around the issue.
Reviewed-by: Kurt Roeckx <kurt at openssl.org>
-----------------------------------------------------------------------
Summary of changes:
crypto/bio/b_addr.c | 10 +++-
crypto/engine/eng_err.c | 4 ++
crypto/engine/eng_init.c | 5 +-
crypto/engine/eng_int.h | 3 +-
crypto/engine/eng_lib.c | 9 ++--
crypto/engine/eng_list.c | 18 +++++--
crypto/engine/tb_asnmth.c | 6 ++-
crypto/err/err.c | 39 +++++++++-----
crypto/ex_data.c | 9 +++-
crypto/init.c | 110 ++++++++++++++++++++++------------------
crypto/mem_dbg.c | 23 +++++----
crypto/rand/md_rand.c | 16 ++++--
doc/crypto/ERR_load_strings.pod | 3 +-
doc/crypto/OPENSSL_malloc.pod | 3 +-
include/internal/thread_once.h | 42 +++++++++++++++
include/openssl/engine.h | 3 ++
include/openssl/err.h | 2 +-
ssl/ssl_cert.c | 7 ++-
ssl/ssl_ciph.c | 7 +--
ssl/ssl_init.c | 19 +++----
20 files changed, 231 insertions(+), 107 deletions(-)
create mode 100644 include/internal/thread_once.h
diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c
index b77fd4b..4e8785f 100644
--- a/crypto/bio/b_addr.c
+++ b/crypto/bio/b_addr.c
@@ -15,6 +15,7 @@
#ifndef OPENSSL_NO_SOCK
#include <openssl/err.h>
#include <openssl/buffer.h>
+#include <internal/thread_once.h>
#include <ctype.h>
CRYPTO_RWLOCK *bio_lookup_lock;
@@ -601,9 +602,10 @@ static int addrinfo_wrap(int family, int socktype,
return 1;
}
-static void do_bio_lookup_init(void)
+DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
{
bio_lookup_lock = CRYPTO_THREAD_lock_new();
+ return (bio_lookup_lock != NULL);
}
/*-
@@ -727,7 +729,11 @@ int BIO_lookup(const char *host, const char *service,
struct servent se_fallback = { NULL, NULL, 0, NULL };
#endif
- CRYPTO_THREAD_run_once(&bio_lookup_init, do_bio_lookup_init);
+ if (!RUN_ONCE(&bio_lookup_init, do_bio_lookup_init)) {
+ BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
+ ret = 0;
+ goto err;
+ }
CRYPTO_THREAD_write_lock(bio_lookup_lock);
he_fallback_address = INADDR_ANY;
diff --git a/crypto/engine/eng_err.c b/crypto/engine/eng_err.c
index c8f628b..5eb8771 100644
--- a/crypto/engine/eng_err.c
+++ b/crypto/engine/eng_err.c
@@ -32,6 +32,8 @@ static ERR_STRING_DATA ENGINE_str_functs[] = {
{ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"},
{ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"},
{ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"},
+ {ERR_FUNC(ENGINE_F_ENGINE_GET_FIRST), "ENGINE_get_first"},
+ {ERR_FUNC(ENGINE_F_ENGINE_GET_LAST), "ENGINE_get_last"},
{ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"},
{ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH),
"ENGINE_get_pkey_asn1_meth"},
@@ -45,6 +47,8 @@ static ERR_STRING_DATA ENGINE_str_functs[] = {
{ERR_FUNC(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT),
"ENGINE_load_ssl_client_cert"},
{ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"},
+ {ERR_FUNC(ENGINE_F_ENGINE_PKEY_ASN1_FIND_STR),
+ "ENGINE_pkey_asn1_find_str"},
{ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"},
{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING),
"ENGINE_set_default_string"},
diff --git a/crypto/engine/eng_init.c b/crypto/engine/eng_init.c
index c51a38d..8be7c6f 100644
--- a/crypto/engine/eng_init.c
+++ b/crypto/engine/eng_init.c
@@ -80,7 +80,10 @@ int ENGINE_init(ENGINE *e)
ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
CRYPTO_THREAD_write_lock(global_engine_lock);
ret = engine_unlocked_init(e);
CRYPTO_THREAD_unlock(global_engine_lock);
diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h
index 6b6ff9f..c604fad 100644
--- a/crypto/engine/eng_int.h
+++ b/crypto/engine/eng_int.h
@@ -18,6 +18,7 @@
# include "internal/cryptlib.h"
# include <internal/engine.h>
+# include <internal/thread_once.h>
#ifdef __cplusplus
extern "C" {
@@ -123,7 +124,7 @@ void engine_pkey_asn1_meths_free(ENGINE *e);
/* Once initialisation function */
extern CRYPTO_ONCE engine_lock_init;
-void do_engine_lock_init(void);
+DECLARE_RUN_ONCE(do_engine_lock_init)
/*
* This is a structure for storing implementations of various crypto
diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c
index f7d0216..67d755a 100644
--- a/crypto/engine/eng_lib.c
+++ b/crypto/engine/eng_lib.c
@@ -16,19 +16,18 @@ CRYPTO_ONCE engine_lock_init = CRYPTO_ONCE_STATIC_INIT;
/* The "new"/"free" stuff first */
-void do_engine_lock_init(void)
+DEFINE_RUN_ONCE(do_engine_lock_init)
{
global_engine_lock = CRYPTO_THREAD_lock_new();
+ return global_engine_lock != NULL;
}
ENGINE *ENGINE_new(void)
{
ENGINE *ret;
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
-
- ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)
+ || (ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
diff --git a/crypto/engine/eng_list.c b/crypto/engine/eng_list.c
index a7252e9..934389f 100644
--- a/crypto/engine/eng_list.c
+++ b/crypto/engine/eng_list.c
@@ -136,7 +136,11 @@ ENGINE *ENGINE_get_first(void)
{
ENGINE *ret;
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_GET_FIRST, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
CRYPTO_THREAD_write_lock(global_engine_lock);
ret = engine_list_head;
if (ret) {
@@ -151,7 +155,11 @@ ENGINE *ENGINE_get_last(void)
{
ENGINE *ret;
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_GET_LAST, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
CRYPTO_THREAD_write_lock(global_engine_lock);
ret = engine_list_tail;
if (ret) {
@@ -279,7 +287,11 @@ ENGINE *ENGINE_by_id(const char *id)
ENGINEerr(ENGINE_F_ENGINE_BY_ID, ERR_R_PASSED_NULL_PARAMETER);
return NULL;
}
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_BY_ID, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
CRYPTO_THREAD_write_lock(global_engine_lock);
iterator = engine_list_head;
while (iterator && (strcmp(id, iterator->id) != 0))
diff --git a/crypto/engine/tb_asnmth.c b/crypto/engine/tb_asnmth.c
index 2a6a4ae..480267d 100644
--- a/crypto/engine/tb_asnmth.c
+++ b/crypto/engine/tb_asnmth.c
@@ -189,7 +189,11 @@ const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe,
fstr.str = str;
fstr.len = len;
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_PKEY_ASN1_FIND_STR, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
CRYPTO_THREAD_write_lock(global_engine_lock);
engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr);
/* If found obtain a structural reference to engine */
diff --git a/crypto/err/err.c b/crypto/err/err.c
index 836fac4..ad1ccd1 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -18,6 +18,7 @@
#include <openssl/buffer.h>
#include <openssl/bio.h>
#include <openssl/opensslconf.h>
+#include <internal/thread_once.h>
static void err_load_strings(int lib, ERR_STRING_DATA *str);
@@ -270,9 +271,10 @@ static void ERR_STATE_free(ERR_STATE *s)
OPENSSL_free(s);
}
-static void do_err_strings_init(void)
+DEFINE_RUN_ONCE_STATIC(do_err_strings_init)
{
err_string_lock = CRYPTO_THREAD_lock_new();
+ return err_string_lock != NULL;
}
void err_cleanup(void)
@@ -284,7 +286,7 @@ void err_cleanup(void)
void ERR_load_ERR_strings(void)
{
#ifndef OPENSSL_NO_ERR
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ RUN_ONCE(&err_string_init, do_err_strings_init);
err_load_strings(0, ERR_str_libraries);
err_load_strings(0, ERR_str_reasons);
@@ -316,11 +318,12 @@ void ERR_load_strings(int lib, ERR_STRING_DATA *str)
err_load_strings(lib, str);
}
-void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
+int ERR_unload_strings(int lib, ERR_STRING_DATA *str)
{
LHASH_OF(ERR_STRING_DATA) *hash;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init))
+ return 0;
CRYPTO_THREAD_write_lock(err_string_lock);
hash = get_hash(0, 0);
@@ -332,11 +335,14 @@ void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
}
}
CRYPTO_THREAD_unlock(err_string_lock);
+
+ return 1;
}
void err_free_strings_int(void)
{
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init))
+ return;
CRYPTO_THREAD_write_lock(err_string_lock);
lh_ERR_STRING_DATA_free(int_error_hash);
@@ -582,7 +588,9 @@ const char *ERR_lib_error_string(unsigned long e)
ERR_STRING_DATA d, *p;
unsigned long l;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
+ return NULL;
+ }
l = ERR_GET_LIB(e);
d.error = ERR_PACK(l, 0, 0);
@@ -595,7 +603,9 @@ const char *ERR_func_error_string(unsigned long e)
ERR_STRING_DATA d, *p;
unsigned long l, f;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
+ return NULL;
+ }
l = ERR_GET_LIB(e);
f = ERR_GET_FUNC(e);
@@ -609,7 +619,9 @@ const char *ERR_reason_error_string(unsigned long e)
ERR_STRING_DATA d, *p = NULL;
unsigned long l, r;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
+ return NULL;
+ }
l = ERR_GET_LIB(e);
r = ERR_GET_REASON(e);
@@ -644,16 +656,17 @@ void ERR_remove_state(unsigned long pid)
}
#endif
-static void err_do_init(void)
+DEFINE_RUN_ONCE_STATIC(err_do_init)
{
- CRYPTO_THREAD_init_local(&err_thread_local, NULL);
+ return CRYPTO_THREAD_init_local(&err_thread_local, NULL);
}
ERR_STATE *ERR_get_state(void)
{
ERR_STATE *state = NULL;
- CRYPTO_THREAD_run_once(&err_init, err_do_init);
+ if (!RUN_ONCE(&err_init, err_do_init))
+ return NULL;
state = CRYPTO_THREAD_get_local(&err_thread_local);
@@ -679,7 +692,9 @@ int ERR_get_next_error_library(void)
{
int ret;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
+ return 0;
+ }
CRYPTO_THREAD_write_lock(err_string_lock);
ret = int_err_library_number++;
diff --git a/crypto/ex_data.c b/crypto/ex_data.c
index 0666393..d9807d5 100644
--- a/crypto/ex_data.c
+++ b/crypto/ex_data.c
@@ -8,6 +8,7 @@
*/
#include "internal/cryptlib_int.h"
+#include "internal/thread_once.h"
#include <openssl/lhash.h>
/*
@@ -35,9 +36,10 @@ static EX_CALLBACKS ex_data[CRYPTO_EX_INDEX__COUNT];
static CRYPTO_RWLOCK *ex_data_lock = NULL;
static CRYPTO_ONCE ex_data_init = CRYPTO_ONCE_STATIC_INIT;
-static void do_ex_data_init(void)
+DEFINE_RUN_ONCE_STATIC(do_ex_data_init)
{
ex_data_lock = CRYPTO_THREAD_lock_new();
+ return ex_data_lock != NULL;
}
/*
@@ -53,7 +55,10 @@ static EX_CALLBACKS *get_and_lock(int class_index)
return NULL;
}
- CRYPTO_THREAD_run_once(&ex_data_init, do_ex_data_init);
+ if (!RUN_ONCE(&ex_data_init, do_ex_data_init)) {
+ CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
if (ex_data_lock == NULL) {
/*
diff --git a/crypto/init.c b/crypto/init.c
index f38129f..ace11da 100644
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -22,6 +22,7 @@
#include <internal/objects.h>
#include <stdlib.h>
#include <assert.h>
+#include <internal/thread_once.h>
static int stopped = 0;
@@ -61,7 +62,7 @@ static CRYPTO_RWLOCK *init_lock = NULL;
static CRYPTO_ONCE base = CRYPTO_ONCE_STATIC_INIT;
static int base_inited = 0;
-static void ossl_init_base(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_base)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n");
@@ -74,20 +75,22 @@ static void ossl_init_base(void)
#ifndef OPENSSL_SYS_UEFI
atexit(OPENSSL_cleanup);
#endif
- init_lock = CRYPTO_THREAD_lock_new();
+ if ((init_lock = CRYPTO_THREAD_lock_new()) == NULL)
+ return 0;
OPENSSL_cpuid_setup();
base_inited = 1;
+ return 1;
}
static CRYPTO_ONCE load_crypto_strings = CRYPTO_ONCE_STATIC_INIT;
static int load_crypto_strings_inited = 0;
-static void ossl_init_no_load_crypto_strings(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_crypto_strings)
{
/* Do nothing in this case */
- return;
+ return 1;
}
-static void ossl_init_load_crypto_strings(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings)
{
/*
* OPENSSL_NO_AUTOERRINIT is provided here to prevent at compile time
@@ -101,10 +104,11 @@ static void ossl_init_load_crypto_strings(void)
err_load_crypto_strings_int();
#endif
load_crypto_strings_inited = 1;
+ return 1;
}
static CRYPTO_ONCE add_all_ciphers = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_add_all_ciphers(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_ciphers)
{
/*
* OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
@@ -117,10 +121,11 @@ static void ossl_init_add_all_ciphers(void)
# endif
openssl_add_all_ciphers_int();
#endif
+ return 1;
}
static CRYPTO_ONCE add_all_digests = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_add_all_digests(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_digests)
{
/*
* OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
@@ -133,18 +138,19 @@ static void ossl_init_add_all_digests(void)
# endif
openssl_add_all_digests_int();
#endif
+ return 1;
}
-static void ossl_init_no_add_algs(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_no_add_algs)
{
/* Do nothing */
- return;
+ return 1;
}
static CRYPTO_ONCE config = CRYPTO_ONCE_STATIC_INIT;
static int config_inited = 0;
static const char *appname;
-static void ossl_init_config(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_config)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr,
@@ -153,8 +159,9 @@ static void ossl_init_config(void)
#endif
openssl_config_int(appname);
config_inited = 1;
+ return 1;
}
-static void ossl_init_no_config(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_no_config)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr,
@@ -162,103 +169,114 @@ static void ossl_init_no_config(void)
#endif
openssl_no_config_int();
config_inited = 1;
+ return 1;
}
static CRYPTO_ONCE async = CRYPTO_ONCE_STATIC_INIT;
static int async_inited = 0;
-static void ossl_init_async(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_async)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_async: async_init()\n");
#endif
- async_init();
+ if (!async_init())
+ return 0;
async_inited = 1;
+ return 1;
}
#ifndef OPENSSL_NO_ENGINE
static CRYPTO_ONCE engine_openssl = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_openssl(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_openssl)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_openssl: "
"engine_load_openssl_int()\n");
# endif
engine_load_openssl_int();
+ return 1;
}
# if !defined(OPENSSL_NO_HW) && \
(defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
static CRYPTO_ONCE engine_cryptodev = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_cryptodev(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_cryptodev)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_cryptodev: "
"engine_load_cryptodev_int()\n");
# endif
engine_load_cryptodev_int();
+ return 1;
}
# endif
# ifndef OPENSSL_NO_RDRAND
static CRYPTO_ONCE engine_rdrand = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_rdrand(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_rdrand)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_rdrand: "
"engine_load_rdrand_int()\n");
# endif
engine_load_rdrand_int();
+ return 1;
}
# endif
static CRYPTO_ONCE engine_dynamic = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_dynamic(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_dynamic)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dynamic: "
"engine_load_dynamic_int()\n");
# endif
engine_load_dynamic_int();
+ return 1;
}
# ifndef OPENSSL_NO_STATIC_ENGINE
# if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
static CRYPTO_ONCE engine_padlock = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_padlock(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_padlock)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_padlock: "
"engine_load_padlock_int()\n");
# endif
engine_load_padlock_int();
+ return 1;
}
# endif
# if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
static CRYPTO_ONCE engine_capi = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_capi(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_capi)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_capi: "
"engine_load_capi_int()\n");
# endif
engine_load_capi_int();
+ return 1;
}
# endif
static CRYPTO_ONCE engine_dasync = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_dasync(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_dasync)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dasync: "
"engine_load_dasync_int()\n");
# endif
engine_load_dasync_int();
+ return 1;
}
# if !defined(OPENSSL_NO_AFALGENG)
static CRYPTO_ONCE engine_afalg = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_afalg(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_afalg)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_afalg: "
"engine_load_afalg_int()\n");
# endif
engine_load_afalg_int();
+ return 1;
}
# endif
# endif
@@ -268,10 +286,11 @@ static void ossl_init_engine_afalg(void)
static CRYPTO_ONCE zlib = CRYPTO_ONCE_STATIC_INIT;
static int zlib_inited = 0;
-static void ossl_init_zlib(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_zlib)
{
/* Do nothing - we need to know about this for the later cleanup */
zlib_inited = 1;
+ return 1;
}
#endif
@@ -464,94 +483,87 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
return 0;
}
- if (!CRYPTO_THREAD_run_once(&base, ossl_init_base))
+ if (!RUN_ONCE(&base, ossl_init_base))
return 0;
if ((opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
- && !CRYPTO_THREAD_run_once(&load_crypto_strings,
- ossl_init_no_load_crypto_strings))
+ && !RUN_ONCE(&load_crypto_strings,
+ ossl_init_no_load_crypto_strings))
return 0;
if ((opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
- && !CRYPTO_THREAD_run_once(&load_crypto_strings,
- ossl_init_load_crypto_strings))
+ && !RUN_ONCE(&load_crypto_strings, ossl_init_load_crypto_strings))
return 0;
if ((opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
- && !CRYPTO_THREAD_run_once(&add_all_ciphers, ossl_init_no_add_algs))
+ && !RUN_ONCE(&add_all_ciphers, ossl_init_no_add_algs))
return 0;
if ((opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
- && !CRYPTO_THREAD_run_once(&add_all_ciphers,
- ossl_init_add_all_ciphers))
+ && !RUN_ONCE(&add_all_ciphers, ossl_init_add_all_ciphers))
return 0;
if ((opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
- && !CRYPTO_THREAD_run_once(&add_all_digests, ossl_init_no_add_algs))
+ && !RUN_ONCE(&add_all_digests, ossl_init_no_add_algs))
return 0;
if ((opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
- && !CRYPTO_THREAD_run_once(&add_all_digests,
- ossl_init_add_all_digests))
+ && !RUN_ONCE(&add_all_digests, ossl_init_add_all_digests))
return 0;
if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG)
- && !CRYPTO_THREAD_run_once(&config, ossl_init_no_config))
+ && !RUN_ONCE(&config, ossl_init_no_config))
return 0;
if (opts & OPENSSL_INIT_LOAD_CONFIG) {
int ret;
CRYPTO_THREAD_write_lock(init_lock);
appname = (settings == NULL) ? NULL : settings->appname;
- ret = CRYPTO_THREAD_run_once(&config, ossl_init_config);
+ ret = RUN_ONCE(&config, ossl_init_config);
CRYPTO_THREAD_unlock(init_lock);
if (!ret)
return 0;
}
if ((opts & OPENSSL_INIT_ASYNC)
- && !CRYPTO_THREAD_run_once(&async, ossl_init_async))
+ && !RUN_ONCE(&async, ossl_init_async))
return 0;
#ifndef OPENSSL_NO_ENGINE
if ((opts & OPENSSL_INIT_ENGINE_OPENSSL)
- && !CRYPTO_THREAD_run_once(&engine_openssl,
- ossl_init_engine_openssl))
+ && !RUN_ONCE(&engine_openssl, ossl_init_engine_openssl))
return 0;
# if !defined(OPENSSL_NO_HW) && \
(defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
if ((opts & OPENSSL_INIT_ENGINE_CRYPTODEV)
- && !CRYPTO_THREAD_run_once(&engine_cryptodev,
- ossl_init_engine_cryptodev))
+ && !RUN_ONCE(&engine_cryptodev, ossl_init_engine_cryptodev))
return 0;
# endif
# ifndef OPENSSL_NO_RDRAND
if ((opts & OPENSSL_INIT_ENGINE_RDRAND)
- && !CRYPTO_THREAD_run_once(&engine_rdrand, ossl_init_engine_rdrand))
+ && !RUN_ONCE(&engine_rdrand, ossl_init_engine_rdrand))
return 0;
# endif
if ((opts & OPENSSL_INIT_ENGINE_DYNAMIC)
- && !CRYPTO_THREAD_run_once(&engine_dynamic,
- ossl_init_engine_dynamic))
+ && !RUN_ONCE(&engine_dynamic, ossl_init_engine_dynamic))
return 0;
# ifndef OPENSSL_NO_STATIC_ENGINE
# if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
if ((opts & OPENSSL_INIT_ENGINE_PADLOCK)
- && !CRYPTO_THREAD_run_once(&engine_padlock,
- ossl_init_engine_padlock))
+ && !RUN_ONCE(&engine_padlock, ossl_init_engine_padlock))
return 0;
# endif
# if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
if ((opts & OPENSSL_INIT_ENGINE_CAPI)
- && !CRYPTO_THREAD_run_once(&engine_capi, ossl_init_engine_capi))
+ && !RUN_ONCE(&engine_capi, ossl_init_engine_capi))
return 0;
# endif
if ((opts & OPENSSL_INIT_ENGINE_DASYNC)
- && !CRYPTO_THREAD_run_once(&engine_dasync, ossl_init_engine_dasync))
+ && !RUN_ONCE(&engine_dasync, ossl_init_engine_dasync))
return 0;
# if !defined(OPENSSL_NO_AFALGENG)
if ((opts & OPENSSL_INIT_ENGINE_AFALG)
- && !CRYPTO_THREAD_run_once(&engine_afalg, ossl_init_engine_afalg))
+ && !RUN_ONCE(&engine_afalg, ossl_init_engine_afalg))
return 0;
# endif
# endif
@@ -564,7 +576,7 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
#ifndef OPENSSL_NO_COMP
if ((opts & OPENSSL_INIT_ZLIB)
- && !CRYPTO_THREAD_run_once(&zlib, ossl_init_zlib))
+ && !RUN_ONCE(&zlib, ossl_init_zlib))
return 0;
#endif
diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c
index 0b48708..0307c02 100644
--- a/crypto/mem_dbg.c
+++ b/crypto/mem_dbg.c
@@ -112,7 +112,8 @@ int CRYPTO_mem_ctrl(int mode)
#else
int ret = mh_mode;
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init))
+ return -1;
CRYPTO_THREAD_write_lock(malloc_lock);
switch (mode) {
@@ -185,7 +186,8 @@ static int mem_check_on(void)
CRYPTO_THREAD_ID cur;
if (mh_mode & CRYPTO_MEM_CHECK_ON) {
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init))
+ return 0;
cur = CRYPTO_THREAD_get_current_id();
CRYPTO_THREAD_read_lock(malloc_lock);
@@ -228,7 +230,9 @@ static int pop_info(void)
{
APP_INFO *current = NULL;
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init))
+ return 0;
+
current = (APP_INFO *)CRYPTO_THREAD_get_local(&appinfokey);
if (current != NULL) {
APP_INFO *next = current->next;
@@ -258,9 +262,8 @@ int CRYPTO_mem_debug_push(const char *info, const char *file, int line)
if (mem_check_on()) {
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
-
- if ((ami = OPENSSL_malloc(sizeof(*ami))) == NULL)
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init)
+ || (ami = OPENSSL_malloc(sizeof(*ami))) == NULL)
goto err;
ami->threadid = CRYPTO_THREAD_get_current_id();
@@ -313,9 +316,8 @@ void CRYPTO_mem_debug_malloc(void *addr, size_t num, int before_p,
if (mem_check_on()) {
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
-
- if ((m = OPENSSL_malloc(sizeof(*m))) == NULL) {
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init)
+ || (m = OPENSSL_malloc(sizeof(*m))) == NULL) {
OPENSSL_free(addr);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
return;
@@ -543,7 +545,8 @@ int CRYPTO_mem_leaks(BIO *b)
/* Ensure all resources are released */
OPENSSL_cleanup();
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init))
+ return -1;
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c
index 9d39831..7924478 100644
--- a/crypto/rand/md_rand.c
+++ b/crypto/rand/md_rand.c
@@ -27,6 +27,8 @@
#include <openssl/err.h>
+#include <internal/thread_once.h>
+
#ifdef OPENSSL_FIPS
# include <openssl/fips.h>
#endif
@@ -85,10 +87,11 @@ static RAND_METHOD rand_meth = {
rand_status
};
-static void do_rand_lock_init(void)
+DEFINE_RUN_ONCE_STATIC(do_rand_lock_init)
{
rand_lock = CRYPTO_THREAD_lock_new();
rand_tmp_lock = CRYPTO_THREAD_lock_new();
+ return rand_lock != NULL && rand_tmp_lock != NULL;
}
RAND_METHOD *RAND_OpenSSL(void)
@@ -141,7 +144,8 @@ static int rand_add(const void *buf, int num, double add)
if (m == NULL)
goto err;
- CRYPTO_THREAD_run_once(&rand_lock_init, do_rand_lock_init);
+ if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))
+ goto err;
/* check if we already have the lock */
if (crypto_lock_rand) {
@@ -339,7 +343,9 @@ static int rand_bytes(unsigned char *buf, int num, int pseudo)
* global 'md'.
*/
- CRYPTO_THREAD_run_once(&rand_lock_init, do_rand_lock_init);
+ if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))
+ goto err_mem;
+
CRYPTO_THREAD_write_lock(rand_lock);
/*
* We could end up in an async engine while holding this lock so ensure
@@ -534,7 +540,9 @@ static int rand_status(void)
int ret;
int do_not_lock;
- CRYPTO_THREAD_run_once(&rand_lock_init, do_rand_lock_init);
+ if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))
+ return 0;
+
cur = CRYPTO_THREAD_get_current_id();
/*
* check if we already have the lock (could happen if a RAND_poll()
diff --git a/doc/crypto/ERR_load_strings.pod b/doc/crypto/ERR_load_strings.pod
index 8071d96..86ee5fd 100644
--- a/doc/crypto/ERR_load_strings.pod
+++ b/doc/crypto/ERR_load_strings.pod
@@ -39,7 +39,8 @@ to user libraries at runtime.
=head1 RETURN VALUE
ERR_load_strings() returns no value. ERR_PACK() return the error code.
-ERR_get_next_error_library() returns a new library number.
+ERR_get_next_error_library() returns zero on failure, otherwise a new
+library number.
=head1 SEE ALSO
diff --git a/doc/crypto/OPENSSL_malloc.pod b/doc/crypto/OPENSSL_malloc.pod
index 574db8a..0060b98 100644
--- a/doc/crypto/OPENSSL_malloc.pod
+++ b/doc/crypto/OPENSSL_malloc.pod
@@ -179,7 +179,8 @@ CRYPTO_set_mem_functions() and CRYPTO_set_mem_debug()
return 1 on success or 0 on failure (almost
always because allocations have already happened).
-CRYPTO_mem_ctrl() returns the previous value of the mode.
+CRYPTO_mem_ctrl() returns -1 if an error occured, otherwise the
+previous value of the mode.
OPENSSL_mem_debug_push() and OPENSSL_mem_debug_pop()
return 1 on success or 0 on failure.
diff --git a/include/internal/thread_once.h b/include/internal/thread_once.h
new file mode 100644
index 0000000..74f6ccb
--- /dev/null
+++ b/include/internal/thread_once.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <openssl/crypto.h>
+
+#define DEFINE_RUN_ONCE(init) \
+ static int init(void); \
+ int init##_ossl_ret_ = 0; \
+ void init##_ossl_(void) \
+ { \
+ init##_ossl_ret_ = init(); \
+ } \
+ static int init(void)
+#define DECLARE_RUN_ONCE(init) \
+ extern int init##_ossl_ret_; \
+ void init##_ossl_(void);
+
+#define DEFINE_RUN_ONCE_STATIC(init) \
+ static int init(void); \
+ static int init##_ossl_ret_ = 0; \
+ static void init##_ossl_(void) \
+ { \
+ init##_ossl_ret_ = init(); \
+ } \
+ static int init(void)
+
+/*
+ * RUN_ONCE - use CRYPTO_THREAD_run_once, and check if the init succeeded
+ * @once: pointer to static object of type CRYPTO_ONCE
+ * @init: function name that was previously given to DEFINE_RUN_ONCE,
+ * DEFINE_RUN_ONCE_STATIC or DECLARE_RUN_ONCE.
+ *
+ * The return value is 1 on success or 0 in case of error.
+ */
+#define RUN_ONCE(once, init) \
+ (CRYPTO_THREAD_run_once(once, init##_ossl_) ? init##_ossl_ret_ : 0)
diff --git a/include/openssl/engine.h b/include/openssl/engine.h
index f359c9e..b1e5c1f 100644
--- a/include/openssl/engine.h
+++ b/include/openssl/engine.h
@@ -773,6 +773,8 @@ void ERR_load_ENGINE_strings(void);
# define ENGINE_F_ENGINE_FINISH 107
# define ENGINE_F_ENGINE_GET_CIPHER 185
# define ENGINE_F_ENGINE_GET_DIGEST 186
+# define ENGINE_F_ENGINE_GET_FIRST 195
+# define ENGINE_F_ENGINE_GET_LAST 196
# define ENGINE_F_ENGINE_GET_NEXT 115
# define ENGINE_F_ENGINE_GET_PKEY_ASN1_METH 193
# define ENGINE_F_ENGINE_GET_PKEY_METH 192
@@ -784,6 +786,7 @@ void ERR_load_ENGINE_strings(void);
# define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
# define ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT 194
# define ENGINE_F_ENGINE_NEW 122
+# define ENGINE_F_ENGINE_PKEY_ASN1_FIND_STR 197
# define ENGINE_F_ENGINE_REMOVE 123
# define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189
# define ENGINE_F_ENGINE_SET_ID 129
diff --git a/include/openssl/err.h b/include/openssl/err.h
index 9dcd27e..60ffc49 100644
--- a/include/openssl/err.h
+++ b/include/openssl/err.h
@@ -232,7 +232,7 @@ void ERR_print_errors(BIO *bp);
void ERR_add_error_data(int num, ...);
void ERR_add_error_vdata(int num, va_list args);
void ERR_load_strings(int lib, ERR_STRING_DATA str[]);
-void ERR_unload_strings(int lib, ERR_STRING_DATA str[]);
+int ERR_unload_strings(int lib, ERR_STRING_DATA str[]);
void ERR_load_ERR_strings(void);
#if OPENSSL_API_COMPAT < 0x10100000L
diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c
index 2a07ee6..c155e78 100644
--- a/ssl/ssl_cert.c
+++ b/ssl/ssl_cert.c
@@ -29,6 +29,7 @@
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include "ssl_locl.h"
+#include "internal/thread_once.h"
static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx, int op,
int bits, int nid, void *other,
@@ -37,17 +38,19 @@ static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx, int o
static CRYPTO_ONCE ssl_x509_store_ctx_once = CRYPTO_ONCE_STATIC_INIT;
static volatile int ssl_x509_store_ctx_idx = -1;
-static void ssl_x509_store_ctx_init(void)
+DEFINE_RUN_ONCE_STATIC(ssl_x509_store_ctx_init)
{
ssl_x509_store_ctx_idx = X509_STORE_CTX_get_ex_new_index(0,
"SSL for verify callback",
NULL, NULL, NULL);
+ return ssl_x509_store_ctx_idx >= 0;
}
int SSL_get_ex_data_X509_STORE_CTX_idx(void)
{
- CRYPTO_THREAD_run_once(&ssl_x509_store_ctx_once, ssl_x509_store_ctx_init);
+ if (!RUN_ONCE(&ssl_x509_store_ctx_once, ssl_x509_store_ctx_init))
+ return -1;
return ssl_x509_store_ctx_idx;
}
diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c
index 2fc4309..2a54f9d 100644
--- a/ssl/ssl_ciph.c
+++ b/ssl/ssl_ciph.c
@@ -46,6 +46,7 @@
#include <openssl/engine.h>
#include <openssl/crypto.h>
#include "ssl_locl.h"
+#include "internal/thread_once.h"
#define SSL_ENC_DES_IDX 0
#define SSL_ENC_3DES_IDX 1
@@ -479,7 +480,7 @@ static int sk_comp_cmp(const SSL_COMP *const *a, const SSL_COMP *const *b)
return ((*a)->id - (*b)->id);
}
-static void do_load_builtin_compressions(void)
+DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)
{
SSL_COMP *comp = NULL;
COMP_METHOD *method = COMP_zlib();
@@ -498,12 +499,12 @@ static void do_load_builtin_compressions(void)
}
}
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+ return 1;
}
static void load_builtin_compressions(void)
{
- CRYPTO_THREAD_run_once(&ssl_load_builtin_comp_once,
- do_load_builtin_compressions);
+ RUN_ONCE(&ssl_load_builtin_comp_once, do_load_builtin_compressions);
}
#endif
diff --git a/ssl/ssl_init.c b/ssl/ssl_init.c
index 66525de..543da13 100644
--- a/ssl/ssl_init.c
+++ b/ssl/ssl_init.c
@@ -14,6 +14,7 @@
#include <openssl/evp.h>
#include <assert.h>
#include "ssl_locl.h"
+#include "internal/thread_once.h"
static int stopped;
@@ -21,7 +22,7 @@ static void ssl_library_stop(void);
static CRYPTO_ONCE ssl_base = CRYPTO_ONCE_STATIC_INIT;
static int ssl_base_inited = 0;
-static void ossl_init_ssl_base(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_ssl_base)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_ssl_base: "
@@ -108,11 +109,12 @@ static void ossl_init_ssl_base(void)
*/
OPENSSL_atexit(ssl_library_stop);
ssl_base_inited = 1;
+ return 1;
}
static CRYPTO_ONCE ssl_strings = CRYPTO_ONCE_STATIC_INIT;
static int ssl_strings_inited = 0;
-static void ossl_init_load_ssl_strings(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_load_ssl_strings)
{
/*
* OPENSSL_NO_AUTOERRINIT is provided here to prevent at compile time
@@ -126,12 +128,13 @@ static void ossl_init_load_ssl_strings(void)
ERR_load_SSL_strings();
#endif
ssl_strings_inited = 1;
+ return 1;
}
-static void ossl_init_no_load_ssl_strings(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_ssl_strings)
{
/* Do nothing in this case */
- return;
+ return 1;
}
static void ssl_library_stop(void)
@@ -193,17 +196,15 @@ int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
| OPENSSL_INIT_ADD_ALL_DIGESTS, settings))
return 0;
- if (!CRYPTO_THREAD_run_once(&ssl_base, ossl_init_ssl_base))
+ if (!RUN_ONCE(&ssl_base, ossl_init_ssl_base))
return 0;
if ((opts & OPENSSL_INIT_NO_LOAD_SSL_STRINGS)
- && !CRYPTO_THREAD_run_once(&ssl_strings,
- ossl_init_no_load_ssl_strings))
+ && !RUN_ONCE(&ssl_strings, ossl_init_no_load_ssl_strings))
return 0;
if ((opts & OPENSSL_INIT_LOAD_SSL_STRINGS)
- && !CRYPTO_THREAD_run_once(&ssl_strings,
- ossl_init_load_ssl_strings))
+ && !RUN_ONCE(&ssl_strings, ossl_init_load_ssl_strings))
return 0;
return 1;
More information about the openssl-commits
mailing list