From 3ab441b1a15d14c3df1435419ac9abb1fcadec71 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 6 Apr 2015 09:30:34 +0300 Subject: [PATCH] Quick band-aid to prevent PRNG prediction This is originally Derek's change from Spork, but sniping it so we can mark this done for now, and can move on with the nextversion. Better solution is to use something like the ISAAC PRNG, which cannot be predicted. --- src/hacklib.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/hacklib.c b/src/hacklib.c index a9c31d42d..1ad5028a9 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -603,24 +603,28 @@ STATIC_DCL struct tm *NDECL(getlt); void setrandom() { - time_t now = getnow(); /* time((TIME_type) 0) */ + unsigned long seed = getnow(); /* time((TIME_type) 0) */ +#ifdef UNIX + /* Quick dirty band-aid to prevent PRNG prediction */ + seed *= getpid(); +#endif /* the types are different enough here that sweeping the different * routine names into one via #defines is even more confusing */ #ifdef RANDOM /* srandom() from sys/share/random.c */ - srandom((unsigned int) now); + srandom((unsigned int) seed); #else # if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) /* system srandom() */ # if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4) (void) # endif - srandom((int) now); + srandom((int) seed); # else # ifdef UNIX /* system srand48() */ - srand48((long) now); + srand48((long) seed); # else /* poor quality system routine */ - srand((int) now); + srand((int) seed); # endif # endif #endif