summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2013-04-17 03:07:41 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2013-04-17 03:07:41 +0000
commit39fdb6d580c789e87c30a268e80913e731d6a8bc (patch)
treed1e8d8c33cf06d193ea1e271f6d28e69ce82d38d /lib
parent2c6c898c62014c00731512d720c1613cef98459c (diff)
use CLOCK_MONOTONIC, and repair future time_t overflow
ok millert guenther
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/res_random.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/libc/net/res_random.c b/lib/libc/net/res_random.c
index d1cb0a0cf45..78cd2c3bb0b 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.18 2013/03/26 17:29:04 eric Exp $ */
+/* $OpenBSD: res_random.c,v 1.19 2013/04/17 03:07:40 deraadt Exp $ */
/*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
@@ -100,7 +100,7 @@ static u_int16_t ru_g;
static u_int16_t ru_counter = 0;
static u_int16_t ru_msb = 0;
static struct prf_ctx *ru_prf = NULL;
-static long ru_reseed;
+static time_t ru_reseed;
static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t);
static void res_initid(void);
@@ -174,7 +174,7 @@ res_initid(void)
u_int16_t j, i;
u_int32_t tmp;
int noprime = 1;
- struct timeval tv;
+ struct timespec ts;
ru_x = arc4random_uniform(RU_M);
@@ -218,23 +218,23 @@ res_initid(void)
if (ru_prf != NULL)
arc4random_buf(ru_prf, sizeof(*ru_prf));
- gettimeofday(&tv, NULL);
- ru_reseed = tv.tv_sec + RU_OUT;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ ru_reseed = ts.tv_sec + RU_OUT;
ru_msb = ru_msb == 0x8000 ? 0 : 0x8000;
}
u_int
res_randomid(void)
{
- struct timeval tv;
+ struct timespec ts;
u_int r;
_THREAD_PRIVATE_MUTEX(random);
- gettimeofday(&tv, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &ts);
_THREAD_PRIVATE_MUTEX_LOCK(random);
- if (ru_counter >= RU_MAX || tv.tv_sec > ru_reseed)
+ if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed)
res_initid();
/* Linear Congruential Generator */