From d18ae25f28e72831dc3c51f78e0735342540098b Mon Sep 17 00:00:00 2001 From: beck <> Date: Sat, 17 Mar 2018 16:20:01 +0000 Subject: Bring in compatibility for OpenSSL 1.1 style init functions. This adds OPENSSL_init_crypto and OPENSSL_init_ssl, as well thread safety modifications for the existing LibreSSL init functions. The initialization routines are called automatically by the normal entry points into the library, as in newer OpenSSL ok jsing@, nits by tb@ and deraadt@ --- src/lib/libcrypto/err/err.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/lib/libcrypto/err/err.c') diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index ffe25bf465..320078da66 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err.c,v 1.45 2017/02/20 23:21:19 beck Exp $ */ +/* $OpenBSD: err.c,v 1.46 2018/03/17 16:20:01 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -109,6 +109,7 @@ * */ +#include #include #include #include @@ -282,6 +283,8 @@ static LHASH_OF(ERR_STATE) *int_thread_hash = NULL; static int int_thread_hash_references = 0; static int int_err_library_number = ERR_LIB_USER; +static pthread_t err_init_thread; + /* Internal function that checks whether "err_fns" is set and if not, sets it to * the defaults. */ static void @@ -650,8 +653,9 @@ ERR_STATE_free(ERR_STATE *s) } void -ERR_load_ERR_strings(void) +ERR_load_ERR_strings_internal(void) { + err_init_thread = pthread_self(); err_fns_check(); #ifndef OPENSSL_NO_ERR err_load_strings(0, ERR_str_libraries); @@ -662,6 +666,21 @@ ERR_load_ERR_strings(void) #endif } + +void +ERR_load_ERR_strings(void) +{ + static pthread_once_t once = PTHREAD_ONCE_INIT; + + if (pthread_equal(pthread_self(), err_init_thread)) + return; /* don't recurse */ + + /* Prayer and clean living lets you ignore errors, OpenSSL style */ + (void) OPENSSL_init_crypto(0, NULL); + + (void) pthread_once(&once, ERR_load_ERR_strings_internal); +} + static void err_load_strings(int lib, ERR_STRING_DATA *str) { @@ -683,6 +702,9 @@ ERR_load_strings(int lib, ERR_STRING_DATA *str) void ERR_unload_strings(int lib, ERR_STRING_DATA *str) { + /* Prayer and clean living lets you ignore errors, OpenSSL style */ + (void) OPENSSL_init_crypto(0, NULL); + while (str->error) { if (lib) str->error |= ERR_PACK(lib, 0, 0); @@ -694,6 +716,9 @@ ERR_unload_strings(int lib, ERR_STRING_DATA *str) void ERR_free_strings(void) { + /* Prayer and clean living lets you ignore errors, OpenSSL style */ + (void) OPENSSL_init_crypto(0, NULL); + err_fns_check(); ERRFN(err_del)(); } @@ -953,6 +978,9 @@ ERR_lib_error_string(unsigned long e) ERR_STRING_DATA d, *p; unsigned long l; + if (!OPENSSL_init_crypto(0, NULL)) + return NULL; + err_fns_check(); l = ERR_GET_LIB(e); d.error = ERR_PACK(l, 0, 0); -- cgit v1.2.3-55-g6feb