From: Richard Levitte Date: Wed, 26 Jul 2000 08:32:00 +0000 (+0000) Subject: There's a deadlock when ssleay_rand_bytes is called the first time, since X-Git-Tag: OpenSSL-engine-0_9_6-beta1~17^2~10 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a4125514f5eb538848622d6c3ae04a3d38fddf91;p=oweals%2Fopenssl.git There's a deadlock when ssleay_rand_bytes is called the first time, since it wants to stir the pool using ssleay_rand_add. This fix provides the possibility to call ssleay_rand_add inside a locked state by simply telling it not to do any locking through a static variable. This isn't the most elegant way one could do this, but it does retain thread safety during the stirring process. --- diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c index 0138f57e55..f874f2fe2c 100644 --- a/crypto/rand/md_rand.c +++ b/crypto/rand/md_rand.c @@ -141,6 +141,11 @@ static long md_count[2]={0,0}; static double entropy=0; static int initialized=0; +/* This should be set to 1 only when ssleay_rand_add() is called inside + an already locked state, so it doesn't try to lock and thereby cause + a hang. And it should always be reset back to 0 before unlocking. */ +static int add_do_not_lock=0; + #ifdef PREDICT int rand_predictable=0; #endif @@ -201,7 +206,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) * hash function. */ - CRYPTO_w_lock(CRYPTO_LOCK_RAND); + if (!add_do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND); st_idx=state_index; /* use our own copies of the counters so that even @@ -233,7 +238,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) md_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0); - CRYPTO_w_unlock(CRYPTO_LOCK_RAND); + if (!add_do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND); for (i=0; i 0)