]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Improved robustness in random seed file handling.
authorSimon Tatham <anakin@pobox.com>
Thu, 7 Nov 2002 20:02:00 +0000 (20:02 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 7 Nov 2002 20:02:00 +0000 (20:02 +0000)
[originally from svn r2201]

noise.c
sshrand.c

diff --git a/noise.c b/noise.c
index a094d25e4dcc03ca9b43341e9e594fef6b21f28f..8ae0f98726b649ab8bece4c96c58fa0ec84693a5 100644 (file)
--- a/noise.c
+++ b/noise.c
@@ -40,6 +40,8 @@ void noise_get_heavy(void (*func) (void *, int))
     }
 
     read_random_seed(func);
+    /* Update the seed immediately, in case another instance uses it. */
+    random_save_seed();
 
     gsps = NULL;
     mod = GetModuleHandle("KERNEL32");
@@ -56,6 +58,7 @@ void random_save_seed(void)
     if (random_active) {
        random_get_savedata(&data, &len);
        write_random_seed(data, len);
+       sfree(data);
     }
 }
 
index 7c401af4a06de6b340b34feaada3bae8a4d426cc..95c7b49255c709cb6d0d94e84a313b836698dbce 100644 (file)
--- a/sshrand.c
+++ b/sshrand.c
@@ -201,7 +201,10 @@ int random_byte(void)
 
 void random_get_savedata(void **data, int *len)
 {
+    void *buf = smalloc(POOLSIZE / 2);
     random_stir();
-    *data = pool.pool + pool.poolpos;
+    memcpy(buf, pool.pool + pool.poolpos, POOLSIZE / 2);
     *len = POOLSIZE / 2;
+    *data = buf;
+    random_stir();
 }