From 39fdb6d580c789e87c30a268e80913e731d6a8bc Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Wed, 17 Apr 2013 03:07:41 +0000 Subject: use CLOCK_MONOTONIC, and repair future time_t overflow ok millert guenther --- lib/libc/net/res_random.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/libc/net') 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 @@ -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 */ -- cgit v1.2.3