summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2016-02-10 13:59:15 +0000
committerMatt Caswell <matt@openssl.org>2016-02-10 17:40:59 +0000
commit0fc32b0718ec210e03b6d8623d4819ed04615a1b (patch)
tree9491a02a740d05b415790bcfeb16eb65f6a06267 /crypto
parent8bd8221be80708825ddb9771d4c9fff67860119b (diff)
The new init functions can now fail so shouldn't be void
The new init functions can fail if the library has already been stopped. We should be able to indicate failure with a 0 return value. Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/async/async.c10
-rw-r--r--crypto/comp/c_zlib.c6
-rw-r--r--crypto/err/err.c3
-rw-r--r--crypto/evp/names.c9
-rw-r--r--crypto/init.c8
5 files changed, 26 insertions, 10 deletions
diff --git a/crypto/async/async.c b/crypto/async/async.c
index db511442ba..af9da35f99 100644
--- a/crypto/async/async.c
+++ b/crypto/async/async.c
@@ -97,7 +97,8 @@ err:
static async_ctx *async_get_ctx(void)
{
- OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL);
+ if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
+ return NULL;
return async_arch_get_ctx();
}
@@ -361,9 +362,12 @@ int ASYNC_init_thread(size_t max_size, size_t init_size)
return 0;
}
- OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL);
+ if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL)) {
+ ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_NOT_INITED);
+ return 0;
+ }
if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ASYNC)) {
- ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE);
+ ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_NOT_INITED);
return 0;
}
diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c
index 619765ceff..baad9c66ee 100644
--- a/crypto/comp/c_zlib.c
+++ b/crypto/comp/c_zlib.c
@@ -289,9 +289,13 @@ COMP_METHOD *COMP_zlib(void)
&& p_inflateInit_ && p_deflateEnd
&& p_deflate && p_deflateInit_ && p_zError)
zlib_loaded++;
+
+ if (!OPENSSL_init_crypto(OPENSSL_INIT_ZLIB, NULL)) {
+ COMP_zlib_cleanup();
+ return meth;
+ }
if (zlib_loaded)
meth = &zlib_stateful_method;
- OPENSSL_init_crypto(OPENSSL_INIT_ZLIB, NULL);
}
}
#endif
diff --git a/crypto/err/err.c b/crypto/err/err.c
index d92e41e3e9..72656339c5 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -894,8 +894,9 @@ ERR_STATE *ERR_get_state(void)
* the first one that we just replaced.
*/
ERR_STATE_free(tmpp);
+
+ /* Ignore failures from these */
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
- /* Ignore failures from this */
ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE);
}
return ret;
diff --git a/crypto/evp/names.c b/crypto/evp/names.c
index f6e5004471..2a5606b040 100644
--- a/crypto/evp/names.c
+++ b/crypto/evp/names.c
@@ -110,7 +110,8 @@ const EVP_CIPHER *EVP_get_cipherbyname(const char *name)
{
const EVP_CIPHER *cp;
- OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL);
+ if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL))
+ return NULL;
cp = (const EVP_CIPHER *)OBJ_NAME_get(name, OBJ_NAME_TYPE_CIPHER_METH);
return (cp);
@@ -120,7 +121,8 @@ const EVP_MD *EVP_get_digestbyname(const char *name)
{
const EVP_MD *cp;
- OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
+ if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL))
+ return NULL;
cp = (const EVP_MD *)OBJ_NAME_get(name, OBJ_NAME_TYPE_MD_METH);
return (cp);
@@ -166,6 +168,7 @@ void EVP_CIPHER_do_all(void (*fn) (const EVP_CIPHER *ciph,
{
struct doall_cipher dc;
+ /* Ignore errors */
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL);
dc.fn = fn;
@@ -179,6 +182,7 @@ void EVP_CIPHER_do_all_sorted(void (*fn) (const EVP_CIPHER *ciph,
{
struct doall_cipher dc;
+ /* Ignore errors */
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL);
dc.fn = fn;
@@ -207,6 +211,7 @@ void EVP_MD_do_all(void (*fn) (const EVP_MD *md,
{
struct doall_md dc;
+ /* Ignore errors */
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
dc.fn = fn;
diff --git a/crypto/init.c b/crypto/init.c
index 3238b80025..f01bd4d93f 100644
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -626,10 +626,10 @@ static const OPENSSL_INIT_SETTINGS *ossl_init_get_setting(
* called prior to any threads making calls to any OpenSSL functions,
* i.e. passing a non-null settings value is assumed to be single-threaded.
*/
-void OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
+int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
{
- /* XXX TODO WARNING To be updated to return a value not assert. */
- assert(!stopped);
+ if (stopped)
+ return 0;
ossl_init_once_run(&base, ossl_init_base);
@@ -716,6 +716,8 @@ void OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
if (opts & OPENSSL_INIT_ZLIB) {
ossl_init_once_run(&zlib, ossl_init_zlib);
}
+
+ return 1;
}
int OPENSSL_atexit(void (*handler)(void))