From: Simon Tatham Date: Sat, 22 Jan 2005 14:51:29 +0000 (+0000) Subject: Owen's just pointed out that random_stir() is capable of recursion. X-Git-Tag: r8855-g4f798d~832 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=f2d48d1b673eed5a9df218a69b26eb1dfdac9a27;p=PuTTY_svn.git 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: http://svn.tartarus.org/sgt/putty@5166 cda61777-01e9-0310-a592-d414129be87e --- 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)