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.c    12 Feb 2015 01:54:57 -0000      1.100
+++ client.c    22 Mar 2015 03:21:08 -0000
@@ -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 -0000      1.18
+++ util.c      22 Mar 2015 03:21:08 -0000
@@ -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

Reply via email to