summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreric <>2015-06-04 19:26:39 +0000
committereric <>2015-06-04 19:26:39 +0000
commit4226557d06a7dad27554658644aa3bd333c25a7d (patch)
tree59b53ec67d4eae4defc03b7adeb88d8c57ae6972
parentee5d49bab98e9108a01c9e83855e50bcf8652cb2 (diff)
downloadopenbsd-4226557d06a7dad27554658644aa3bd333c25a7d.tar.gz
openbsd-4226557d06a7dad27554658644aa3bd333c25a7d.tar.bz2
openbsd-4226557d06a7dad27554658644aa3bd333c25a7d.zip
force reseeding if pid has changed.
ok deraadt@
-rw-r--r--src/lib/libc/net/res_random.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lib/libc/net/res_random.c b/src/lib/libc/net/res_random.c
index f28692f7c2..394072c813 100644
--- a/src/lib/libc/net/res_random.c
+++ b/src/lib/libc/net/res_random.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_random.c,v 1.21 2014/07/20 04:22:34 guenther Exp $ */ 1/* $OpenBSD: res_random.c,v 1.22 2015/06/04 19:26:39 eric Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> 4 * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
@@ -101,6 +101,7 @@ static u_int16_t ru_counter = 0;
101static u_int16_t ru_msb = 0; 101static u_int16_t ru_msb = 0;
102static struct prf_ctx *ru_prf = NULL; 102static struct prf_ctx *ru_prf = NULL;
103static time_t ru_reseed; 103static time_t ru_reseed;
104static pid_t ru_pid;
104 105
105static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t); 106static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t);
106static void res_initid(void); 107static void res_initid(void);
@@ -227,15 +228,19 @@ u_int
227res_randomid(void) 228res_randomid(void)
228{ 229{
229 struct timespec ts; 230 struct timespec ts;
231 pid_t pid;
230 u_int r; 232 u_int r;
231 _THREAD_PRIVATE_MUTEX(random); 233 _THREAD_PRIVATE_MUTEX(random);
232 234
233 clock_gettime(CLOCK_MONOTONIC, &ts); 235 clock_gettime(CLOCK_MONOTONIC, &ts);
236 pid = getpid();
234 237
235 _THREAD_PRIVATE_MUTEX_LOCK(random); 238 _THREAD_PRIVATE_MUTEX_LOCK(random);
236 239
237 if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed) 240 if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed || pid != ru_pid) {
238 res_initid(); 241 res_initid();
242 ru_pid = pid;
243 }
239 244
240 /* Linear Congruential Generator */ 245 /* Linear Congruential Generator */
241 ru_x = (ru_a * ru_x + ru_b) % RU_M; 246 ru_x = (ru_a * ru_x + ru_b) % RU_M;