summaryrefslogtreecommitdiffstats
path: root/crypto/context.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2021-04-15 16:46:35 +0100
committerMatt Caswell <matt@openssl.org>2021-04-19 10:50:29 +0100
commit92b20fb8f742d50ca9eae8c28a855df94b9a3783 (patch)
tree8abd7f8e09d25bb6c51d0efd1febe6a5d581a82f /crypto/context.c
parent145a4c871d9632a6eb2145f8a2b417bec58e7ee5 (diff)
Change the semantics of OSSL_LIB_CTX_set0_default() NULL handling
Change things so that passing NULL to OSSL_LIB_CTX_set0_default() means keep the current library context unchanged. This has the advantage of simplifying error handling, e.g. you can call OSSL_LIB_CTX_set0_default in an error/finalisation block safe in the knowledge the if the "prevctx" was never set then it will be a no-op (like calling a "free" function with NULL). Fixes #14593 Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14890)
Diffstat (limited to 'crypto/context.c')
-rw-r--r--crypto/context.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/crypto/context.c b/crypto/context.c
index 6c088e6628..07fff535ff 100644
--- a/crypto/context.c
+++ b/crypto/context.c
@@ -204,9 +204,11 @@ OSSL_LIB_CTX *OSSL_LIB_CTX_set0_default(OSSL_LIB_CTX *libctx)
#ifndef FIPS_MODULE
OSSL_LIB_CTX *current_defctx;
- if ((current_defctx = get_default_context()) != NULL
- && set_default_context(libctx))
+ if ((current_defctx = get_default_context()) != NULL) {
+ if (libctx != NULL)
+ set_default_context(libctx);
return current_defctx;
+ }
#endif
return NULL;