From: Matt Caswell Date: Thu, 15 Apr 2021 15:46:35 +0000 (+0100) Subject: Change the semantics of OSSL_LIB_CTX_set0_default() NULL handling X-Git-Tag: openssl-3.0.0-alpha15~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=92b20fb8f742d50ca9eae8c28a855df94b9a3783;p=thirdparty%2Fopenssl.git 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 Reviewed-by: Tim Hudson Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/14890) --- diff --git a/crypto/context.c b/crypto/context.c index 6c088e6628c..07fff535ff9 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; diff --git a/doc/man3/OSSL_LIB_CTX.pod b/doc/man3/OSSL_LIB_CTX.pod index 01b6a47b487..a23a10f5cea 100644 --- a/doc/man3/OSSL_LIB_CTX.pod +++ b/doc/man3/OSSL_LIB_CTX.pod @@ -41,7 +41,9 @@ default OpenSSL library context. OSSL_LIB_CTX_set0_default() sets the default OpenSSL library context to be I 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 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), as the default library context when