summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2015-06-04 19:26:40 +0000
committerEric Faurot <eric@cvs.openbsd.org>2015-06-04 19:26:40 +0000
commitc0157819ef53872ec76be33bc35df11c11080859 (patch)
tree9bb613b4c7445462b45bed4c73be0bba69178abd /lib
parent4be050a03161e64b0d185e4c2491e5f0e14a979b (diff)
force reseeding if pid has changed.
ok deraadt@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/res_random.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/libc/net/res_random.c b/lib/libc/net/res_random.c
index f28692f7c2a..394072c8130 100644
--- a/lib/libc/net/res_random.c
+++ b/lib/libc/net/res_random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_random.c,v 1.21 2014/07/20 04:22:34 guenther Exp $ */
+/* $OpenBSD: res_random.c,v 1.22 2015/06/04 19:26:39 eric Exp $ */
/*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
@@ -101,6 +101,7 @@ static u_int16_t ru_counter = 0;
static u_int16_t ru_msb = 0;
static struct prf_ctx *ru_prf = NULL;
static time_t ru_reseed;
+static pid_t ru_pid;
static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t);
static void res_initid(void);
@@ -227,15 +228,19 @@ u_int
res_randomid(void)
{
struct timespec ts;
+ pid_t pid;
u_int r;
_THREAD_PRIVATE_MUTEX(random);
clock_gettime(CLOCK_MONOTONIC, &ts);
+ pid = getpid();
_THREAD_PRIVATE_MUTEX_LOCK(random);
- if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed)
+ if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed || pid != ru_pid) {
res_initid();
+ ru_pid = pid;
+ }
/* Linear Congruential Generator */
ru_x = (ru_a * ru_x + ru_b) % RU_M;