Check rand_meth_lock existence before trying to lock it

There are situations during exit clean up where dependent libraries
might be using TLS to finalize stuff but that might crash because
the rand_meth_lock can get freed and there is still an attempt to
get rand bytes. This change makes sure that things fail nicely.

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27119)

(cherry picked from commit 4eb3eea7a3)
This commit is contained in:
Jakub Zelenka 2025-03-22 12:04:23 +01:00 committed by Tomas Mraz
parent 3d6b07f850
commit 6982df65ca
1 changed files with 3 additions and 0 deletions

View File

@ -194,6 +194,9 @@ const RAND_METHOD *RAND_get_rand_method(void)
if (!RUN_ONCE(&rand_init, do_rand_init))
return NULL;
if (rand_meth_lock == NULL)
return NULL;
if (!CRYPTO_THREAD_read_lock(rand_meth_lock))
return NULL;
tmp_meth = default_RAND_meth;