From: Nikos Mavrogiannopoulos Date: Thu, 24 Feb 2011 16:19:29 +0000 (+0100) Subject: Detect fork() in the random number generator and reseed. X-Git-Tag: gnutls_2_99_0~173 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ed0bf779a35bccde60fa8d8006d6e12a3a4ecd6;p=thirdparty%2Fgnutls.git Detect fork() in the random number generator and reseed. --- 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 #include #include +#include /* getpid */ #ifdef HAVE_GETRUSAGE #include #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); } }