From c6719ffb7747607ca38df0fbf4b54d6d85e40674 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bodo=20M=C3=B6ller?= Date: Tue, 24 Jul 2001 12:33:41 +0000 Subject: [PATCH] Avoid race condition. Submitted by: Travis Vitek --- CHANGES | 5 ++++- crypto/rand/md_rand.c | 6 ++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 50a26c6f50..4d0063fb85 100644 --- a/CHANGES +++ b/CHANGES @@ -4,7 +4,10 @@ Changes between 0.9.6b and 0.9.6c [XX xxx XXXX] - *) + *) In crypto/rand/md_rand.c, set 'locking_thread' to current thread's ID + *before* setting the 'crypto_lock_rand' flag. The previous code had + a race condition if 0 is a valid thread ID. + [Travis Vitek ] Changes between 0.9.6a and 0.9.6b [9 Jul 2001] diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c index 04b9d695b0..0db87d4510 100644 --- a/crypto/rand/md_rand.c +++ b/crypto/rand/md_rand.c @@ -361,8 +361,8 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) CRYPTO_w_lock(CRYPTO_LOCK_RAND); /* prevent ssleay_rand_bytes() from trying to obtain the lock again */ - crypto_lock_rand = 1; locking_thread = CRYPTO_thread_id(); + crypto_lock_rand = 1; if (!initialized) { @@ -435,7 +435,6 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) /* before unlocking, we must clear 'crypto_lock_rand' */ crypto_lock_rand = 0; - locking_thread = 0; CRYPTO_w_unlock(CRYPTO_LOCK_RAND); while (num > 0) @@ -528,8 +527,8 @@ static int ssleay_rand_status(void) CRYPTO_w_lock(CRYPTO_LOCK_RAND); /* prevent ssleay_rand_bytes() from trying to obtain the lock again */ - crypto_lock_rand = 1; locking_thread = CRYPTO_thread_id(); + crypto_lock_rand = 1; } if (!initialized) @@ -544,7 +543,6 @@ static int ssleay_rand_status(void) { /* before unlocking, we must clear 'crypto_lock_rand' */ crypto_lock_rand = 0; - locking_thread = 0; CRYPTO_w_unlock(CRYPTO_LOCK_RAND); } -- 2.25.1