Re: ntpd:support adjusting initial time = y2k36 on 32-bit time_t platforms

2015-03-27 Thread Brent Cook
On Mon, Mar 23, 2015 at 10:42 AM, Alexey Suslikov
alexey.susli...@gmail.com wrote:
 Brent Cook busterb at gmail.com writes:

 + T4 += (uint64_t)tv.tv_sec + JAN_1970 + 1.0e-6 *
 tv.tv_usec;

 snip

 + return ((uint64_t)tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec);

 snip

 Can gettime_from_timeval be used over the code instead of repeating
 same chunk?

 T4 += gettime_from_timeval(...

 return gettime_from_timeval(...

Good point Alexy. That is the right way to go.



Re: ntpd:support adjusting initial time = y2k36 on 32-bit time_t platforms

2015-03-23 Thread Alexey Suslikov
Brent Cook busterb at gmail.com writes:

 + T4 += (uint64_t)tv.tv_sec + JAN_1970 + 1.0e-6 * 
tv.tv_usec;

snip

 + return ((uint64_t)tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec);

snip

Can gettime_from_timeval be used over the code instead of repeating
same chunk?

T4 += gettime_from_timeval(...

return gettime_from_timeval(...



ntpd:support adjusting initial time = y2k36 on 32-bit time_t platforms

2015-03-21 Thread Brent Cook
This came up in the OpenNTPD issue tracker:
https://github.com/openntpd-portable/openntpd-openbsd/pull/4

The issue is an overflow when calculating time offsets with a 32-bit
time_t in early 2036. The main reason to fix it in now, in 2015, is that
OpenNTPD fails to adjust time if such a system simply has a bad initial
time value.

I could maintain this as a local patch on the portable tree, but it
felt like this one should be upstream rather than hidden away in a patch
file.

Suggestions on better wording or oks?

Maybe 'sorry in advance for prolonging the Android uprising an
additional 2 years'.

Index: client.c
===
RCS file: /cvs/src/usr.sbin/ntpd/client.c,v
retrieving revision 1.100
diff -u -p -u -p -r1.100 client.c
--- client.c12 Feb 2015 01:54:57 -  1.100
+++ client.c22 Mar 2015 03:21:08 -
@@ -258,7 +258,11 @@ client_dispatch(struct ntp_peer *p, u_in
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;
+   /*
+* Account for overflow that occurs on OSes that still
+* have a 32-bit time_t.
+*/
+   T4 += (uint64_t)tv.tv_sec + JAN_1970 + 1.0e-6 * 
tv.tv_usec;
break;
}
}
Index: util.c
===
RCS file: /cvs/src/usr.sbin/ntpd/util.c,v
retrieving revision 1.18
diff -u -p -u -p -r1.18 util.c
--- util.c  10 Feb 2015 11:46:39 -  1.18
+++ util.c  22 Mar 2015 03:21:08 -
@@ -45,13 +45,21 @@ gettime(void)
if (gettimeofday(tv, NULL) == -1)
fatal(gettimeofday);

-   return (tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec);
+   /*
+* Account for overflow that occurs on OSes that still
+* have a 32-bit time_t.
+*/
+   return ((uint64_t)tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec);
 }

 double
 gettime_from_timeval(struct timeval *tv)
 {
-   return (tv-tv_sec + JAN_1970 + 1.0e-6 * tv-tv_usec);
+   /*
+* Account for overflow that occurs on OSes that still
+* have a 32-bit time_t.
+*/
+   return ((uint64_t)tv-tv_sec + JAN_1970 + 1.0e-6 * tv-tv_usec);
 }

 time_t