diff --git a/CHANGES b/CHANGES index 5098839168..af5c527397 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1078. [bug] We failed to correct bad tv_usec values in one case. + [RT #1966] + 1077. [func] Do not accept further recursive clients when the total number of of recursive lookups being processed exceeds max-recursive-clients, even diff --git a/lib/isc/unix/stdtime.c b/lib/isc/unix/stdtime.c index 6ca1fce2fb..56efc41f8d 100644 --- a/lib/isc/unix/stdtime.c +++ b/lib/isc/unix/stdtime.c @@ -15,17 +15,50 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: stdtime.c,v 1.11 2001/02/13 13:24:09 marka Exp $ */ +/* $Id: stdtime.c,v 1.12 2001/10/30 02:39:33 marka Exp $ */ #include #include /* NULL */ +#include #include #include #include +#ifndef ISC_FIX_TV_USEC +#define ISC_FIX_TV_USEC 1 +#endif + +#define US_PER_S 1000000 + +#if ISC_FIX_TV_USEC +static inline void +fix_tv_usec(struct timeval *tv) { + isc_boolean_t fixed = ISC_FALSE; + + if (tv->tv_usec < 0) { + fixed = ISC_TRUE; + do { + tv->tv_sec -= 1; + tv->tv_usec += US_PER_S; + } while (tv->tv_usec < 0); + } else if (tv->tv_usec >= US_PER_S) { + fixed = ISC_TRUE; + do { + tv->tv_sec += 1; + tv->tv_usec -= US_PER_S; + } while (tv->tv_usec >=US_PER_S); + } + /* + * Call syslog directly as we are called from the logging functions. + */ + if (fixed) + syslog(LOG_ERR, "gettimeofday returned bad tv_usec: corrected"); +} +#endif + void isc_stdtime_get(isc_stdtime_t *t) { struct timeval tv; @@ -39,7 +72,12 @@ isc_stdtime_get(isc_stdtime_t *t) { RUNTIME_CHECK(gettimeofday(&tv, NULL) != -1); - INSIST(tv.tv_usec >= 0 && tv.tv_usec < 1000000); +#if ISC_FIX_TV_USEC + fix_tv_usec(&tv); + INSIST(tv.tv_usec >= 0); +#else + INSIST(tv.tv_usec >= 0 && tv.tv_usec < US_PER_S); +#endif *t = (unsigned int)tv.tv_sec; }