diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2011-02-24 17:19:29 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2011-02-24 17:23:22 +0100 |
commit | 786d7ec0a1c0967a671c5f9415f5a07c0cc6d787 (patch) | |
tree | af05e47895baba44c58ebe360449343dabc60b6f | |
parent | 2fa2546be742aebfd97d039cabd86d941d7bc04f (diff) | |
download | gnutls-786d7ec0a1c0967a671c5f9415f5a07c0cc6d787.tar.gz |
Detect fork() in the random number generator and reseed.
-rw-r--r-- | lib/nettle/rnd.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/nettle/rnd.c b/lib/nettle/rnd.c index e623c90db5..9ccb398fe3 100644 --- a/lib/nettle/rnd.c +++ b/lib/nettle/rnd.c @@ -155,6 +155,7 @@ wrap_nettle_rnd_deinit (void *ctx) #include <sys/time.h> #include <fcntl.h> #include <locks.h> +#include <unistd.h> /* getpid */ #ifdef HAVE_GETRUSAGE #include <sys/resource.h> #endif @@ -346,6 +347,7 @@ do_device_source_egd (int init) static int do_device_source (int init) { + static pid_t pid; /* detect fork() */ int ret; static int (*do_source) (int init) = NULL; /* using static var here is ok since we are @@ -354,6 +356,8 @@ do_device_source (int init) if (init == 1) { + pid = getpid(); + do_source = do_device_source_urandom; ret = do_source (init); if (ret < 0) @@ -372,6 +376,12 @@ do_device_source (int init) } else { + if (getpid() != pid) + { /* fork() detected */ + device_last_read = 0; + pid = getpid(); + } + return do_source (init); } } |