]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Change the semantics of OSSL_LIB_CTX_set0_default() NULL handling
authorMatt Caswell <matt@openssl.org>
Thu, 15 Apr 2021 15:46:35 +0000 (16:46 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 19 Apr 2021 09:50:29 +0000 (10:50 +0100)
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)

crypto/context.c
doc/man3/OSSL_LIB_CTX.pod

index 6c088e6628c5494499dd70661bdcc5b401b8e600..07fff535ff9cdb9b3222429b02f02e9645db9442 100644 (file)
@@ -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;
index 01b6a47b487c82188dc4b24f1bf6f1c1fd7bb4ce..a23a10f5ceae0d266c66ab0e575ae4ddad59d632 100644 (file)
@@ -41,7 +41,9 @@ default OpenSSL library context.
 OSSL_LIB_CTX_set0_default() sets the default OpenSSL library context to be
 I<ctx> in the current thread.  The previous default library context is
 returned.  Care should be taken by the caller to restore the previous
-default library context with a subsequent call of this function.
+default library context with a subsequent call of this function. If I<ctx> is
+NULL then no change is made to the default library context, but a pointer to
+the current library context is still returned.
 
 Care should be taken when changing the default library context and starting
 async jobs (see L<ASYNC_start_job(3)>), as the default library context when