]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Check rand_meth_lock existence before trying to lock it
authorJakub Zelenka <jakub.openssl@gmail.com>
Sat, 22 Mar 2025 11:04:23 +0000 (12:04 +0100)
committerTomas Mraz <tomas@openssl.org>
Tue, 13 May 2025 09:38:29 +0000 (11:38 +0200)
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)

crypto/rand/rand_lib.c

index 365774b479297a57e95fe11105a6f0b0406481d7..5b9713eda629e327d71acbb0f77272e7095925d1 100644 (file)
@@ -289,6 +289,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;