diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2018-03-17 16:20:02 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2018-03-17 16:20:02 +0000 |
commit | d83b0021084a06853c2e11f06f5db729bf3d6b63 (patch) | |
tree | 9bc3c82ef5d22ad7695889a5ca723dc30571fe51 /lib/libcrypto/err | |
parent | f1c695dbced730499b0200286f944d2c271be41d (diff) |
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@
Diffstat (limited to 'lib/libcrypto/err')
-rw-r--r-- | lib/libcrypto/err/err.c | 32 | ||||
-rw-r--r-- | lib/libcrypto/err/err_all.c | 18 |
2 files changed, 44 insertions, 6 deletions
diff --git a/lib/libcrypto/err/err.c b/lib/libcrypto/err/err.c index ffe25bf4656..320078da664 100644 --- a/lib/libcrypto/err/err.c +++ b/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 <pthread.h> #include <stdarg.h> #include <stdio.h> #include <string.h> @@ -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); diff --git a/lib/libcrypto/err/err_all.c b/lib/libcrypto/err/err_all.c index 40009cbe882..24de3c9c155 100644 --- a/lib/libcrypto/err/err_all.c +++ b/lib/libcrypto/err/err_all.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err_all.c,v 1.23 2016/10/19 16:49:11 jsing Exp $ */ +/* $OpenBSD: err_all.c,v 1.24 2018/03/17 16:20:01 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -56,6 +56,7 @@ * [including the GNU Public Licence.] */ +#include <pthread.h> #include <stdio.h> #include <openssl/opensslconf.h> @@ -103,11 +104,13 @@ #include <openssl/gost.h> #endif -void -ERR_load_crypto_strings(void) +void ERR_load_ERR_strings_internal(void); + +static void +ERR_load_crypto_strings_internal(void) { #ifndef OPENSSL_NO_ERR - ERR_load_ERR_strings(); /* include error strings for SYSerr */ + ERR_load_ERR_strings_internal(); /* include error strings for SYSerr */ ERR_load_BN_strings(); #ifndef OPENSSL_NO_RSA ERR_load_RSA_strings(); @@ -153,3 +156,10 @@ ERR_load_crypto_strings(void) #endif #endif } + +void +ERR_load_crypto_strings(void) +{ + static pthread_once_t loaded = PTHREAD_ONCE_INIT; + (void) pthread_once(&loaded, ERR_load_crypto_strings_internal); +} |