From ab076e024dead93707ab637800ddcdad0a289e0a Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 22 Jan 2005 14:51:29 +0000 Subject: [PATCH] Owen's just pointed out that random_stir() is capable of recursion. I'm sure I didn't mean that to happen! Added a lock to stop it. git-svn-id: svn://svn.tartarus.org/sgt/putty@5166 cda61777-01e9-0310-a592-d414129be87e --- sshrand.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sshrand.c b/sshrand.c index 43b81234..26fcfe52 100644 --- a/sshrand.c +++ b/sshrand.c @@ -40,6 +40,8 @@ struct RandPool { unsigned char incomingb[HASHINPUT]; int incomingpos; + + int stir_pending; }; static struct RandPool pool; @@ -52,6 +54,14 @@ static void random_stir(void) word32 digest[HASHSIZE / sizeof(word32)]; int i, j, k; + /* + * noise_get_light will call random_add_noise, which may call + * back to here. Prevent recursive stirs. + */ + if (pool.stir_pending) + return; + pool.stir_pending = TRUE; + noise_get_light(random_add_noise); SHATransform((word32 *) pool.incoming, (word32 *) pool.incomingb); @@ -115,6 +125,8 @@ static void random_stir(void) memcpy(pool.incoming, digest, sizeof(digest)); pool.poolpos = sizeof(pool.incoming); + + pool.stir_pending = FALSE; } void random_add_noise(void *noise, int length) -- 2.11.0