From 6982df65ca7d4e42997d2ccc229d1401d1036239 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sat, 22 Mar 2025 12:04:23 +0100 Subject: [PATCH] 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 Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27119) (cherry picked from commit 4eb3eea7a38eccfa2790020188d1d59dc68d8755) --- crypto/rand/rand_lib.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index d36c7782964..34c7ae73abb 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -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; -- 2.47.2