summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/context.c14
-rw-r--r--crypto/rand/rand_lib.c6
2 files changed, 16 insertions, 4 deletions
diff --git a/crypto/context.c b/crypto/context.c
index 96216abcda..9bb0577adf 100644
--- a/crypto/context.c
+++ b/crypto/context.c
@@ -57,17 +57,23 @@ struct ossl_lib_ctx_st {
int ossl_lib_ctx_write_lock(OSSL_LIB_CTX *ctx)
{
- return CRYPTO_THREAD_write_lock(ossl_lib_ctx_get_concrete(ctx)->lock);
+ if ((ctx = ossl_lib_ctx_get_concrete(ctx)) == NULL)
+ return 0;
+ return CRYPTO_THREAD_write_lock(ctx->lock);
}
int ossl_lib_ctx_read_lock(OSSL_LIB_CTX *ctx)
{
- return CRYPTO_THREAD_read_lock(ossl_lib_ctx_get_concrete(ctx)->lock);
+ if ((ctx = ossl_lib_ctx_get_concrete(ctx)) == NULL)
+ return 0;
+ return CRYPTO_THREAD_read_lock(ctx->lock);
}
int ossl_lib_ctx_unlock(OSSL_LIB_CTX *ctx)
{
- return CRYPTO_THREAD_unlock(ossl_lib_ctx_get_concrete(ctx)->lock);
+ if ((ctx = ossl_lib_ctx_get_concrete(ctx)) == NULL)
+ return 0;
+ return CRYPTO_THREAD_unlock(ctx->lock);
}
int ossl_lib_ctx_is_child(OSSL_LIB_CTX *ctx)
@@ -421,7 +427,7 @@ static OSSL_LIB_CTX *get_default_context(void)
{
OSSL_LIB_CTX *current_defctx = get_thread_default_context();
- if (current_defctx == NULL)
+ if (current_defctx == NULL && default_context_inited)
current_defctx = &default_context_int;
return current_defctx;
}
diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c
index ad66cd7791..a15614faa5 100644
--- a/crypto/rand/rand_lib.c
+++ b/crypto/rand/rand_lib.c
@@ -818,6 +818,9 @@ EVP_RAND_CTX *RAND_get0_public(OSSL_LIB_CTX *ctx)
return NULL;
ctx = ossl_lib_ctx_get_concrete(ctx);
+
+ if (ctx == NULL)
+ return NULL;
/*
* If the private is also NULL then this is the first time we've
* used this thread.
@@ -851,6 +854,9 @@ EVP_RAND_CTX *RAND_get0_private(OSSL_LIB_CTX *ctx)
return NULL;
ctx = ossl_lib_ctx_get_concrete(ctx);
+
+ if (ctx == NULL)
+ return NULL;
/*
* If the public is also NULL then this is the first time we've
* used this thread.