Browse Source

Avoid overflow on 32-bit time_t systems converting timeval to NTP time.

Original fix from Romuald Delavergne. ok henning@
OPENBSD_5_8
bcook 9 years ago
parent
commit
d72cee2563
2 changed files with 8 additions and 5 deletions
  1. +2
    -2
      src/usr.sbin/ntpd/client.c
  2. +6
    -3
      src/usr.sbin/ntpd/util.c

+ 2
- 2
src/usr.sbin/ntpd/client.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: client.c,v 1.100 2015/02/12 01:54:57 reyk Exp $ */
/* $OpenBSD: client.c,v 1.101 2015/03/28 03:49:01 bcook Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -258,7 +258,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_TIMESTAMP) {
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
T4 += tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec;
T4 += gettime_from_timeval(&tv);
break;
}
}


+ 6
- 3
src/usr.sbin/ntpd/util.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: util.c,v 1.18 2015/02/10 11:46:39 reyk Exp $ */
/* $OpenBSD: util.c,v 1.19 2015/03/28 03:49:01 bcook Exp $ */
/*
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
@ -45,13 +45,16 @@ gettime(void)
if (gettimeofday(&tv, NULL) == -1)
fatal("gettimeofday");
return (tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec);
return (gettime_from_timeval(&tv));
}
double
gettime_from_timeval(struct timeval *tv)
{
return (tv->tv_sec + JAN_1970 + 1.0e-6 * tv->tv_usec);
/*
* Account for overflow on OSes that have a 32-bit time_t.
*/
return ((uint64_t)tv->tv_sec + JAN_1970 + 1.0e-6 * tv->tv_usec);
}
time_t


Loading…
Cancel
Save