mirror of https://github.com/openssl/openssl.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 <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)
This commit is contained in:
		
							parent
							
								
									145a4c871d
								
							
						
					
					
						commit
						92b20fb8f7
					
				|  | @ -204,9 +204,11 @@ OSSL_LIB_CTX *OSSL_LIB_CTX_set0_default(OSSL_LIB_CTX *libctx) | ||||||
| #ifndef FIPS_MODULE | #ifndef FIPS_MODULE | ||||||
|     OSSL_LIB_CTX *current_defctx; |     OSSL_LIB_CTX *current_defctx; | ||||||
| 
 | 
 | ||||||
|     if ((current_defctx = get_default_context()) != NULL |     if ((current_defctx = get_default_context()) != NULL) { | ||||||
|         && set_default_context(libctx)) |         if (libctx != NULL) | ||||||
|  |             set_default_context(libctx); | ||||||
|         return current_defctx; |         return current_defctx; | ||||||
|  |     } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|     return NULL; |     return NULL; | ||||||
|  |  | ||||||
|  | @ -41,7 +41,9 @@ default OpenSSL library context. | ||||||
| OSSL_LIB_CTX_set0_default() sets the default OpenSSL library context to be | 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 | I<ctx> in the current thread.  The previous default library context is | ||||||
| returned.  Care should be taken by the caller to restore the previous | 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 | 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 | async jobs (see L<ASYNC_start_job(3)>), as the default library context when | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue