]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2772] adj_systime overflows tv_usec
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 6 Dec 2015 19:19:32 +0000 (20:19 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 6 Dec 2015 19:19:32 +0000 (20:19 +0100)
bk: 56648a44QuJ_xltpef9gRwTLhqD5aA

ChangeLog
libntp/systime.c

index b4a8ab7659c2485c7f1a66c94846698ad5912c05..4a1b12a115d8f22d1c7b0125f8c7c55804f7f9ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,7 @@
 * CID 1341681: Nits in sntp/tests/keyFile.c.  HStenn.
 * CID 1341682: Nit in libntp/authreadkeys.c.  HStenn.
 * CID 1341684: Nit in tests/ntpd/t-ntp_signd.c.  HStenn.
+* [Bug 2772] adj_systime overflows tv_usec. perlinger@ntp.org
 * [Bug 2829] Look at pipe_fds in ntpd.c  (did so. perlinger@ntp.org)
 * [Bug 2887] stratum -1 config results as showing value 99
   - fudge stratum only accepts values [0..16]. perlinger@ntp.org
index c89d157cb2ada837d45b5e6ea2998e1ad6a47eaa..29f1e86375e2c73130ffe1c2116dc5f4e988d763 100644 (file)
@@ -323,9 +323,18 @@ adj_systime(
        else
                quant = 1e-6;
        ticks = (long)(dtemp / quant + .5);
-       adjtv.tv_usec = (long)(ticks * quant * 1e6);
-       dtemp -= adjtv.tv_usec / 1e6;
-       sys_residual = dtemp;
+       adjtv.tv_usec = (long)(ticks * quant * 1.e6 + .5);
+       /* The rounding in the conversions could us push over the
+        * limits: make sure the result is properly normalised!
+        * note: sign comes later, all numbers non-negative here.
+        */
+       if (adjtv.tv_usec >= 1000000) {
+               adjtv.tv_sec  += 1;
+               adjtv.tv_usec -= 1000000;
+               dtemp         -= 1.;
+       }
+       /* set the new residual with leftover from correction */
+       sys_residual = dtemp - adjtv.tv_usec * 1.e-6;
 
        /*
         * Convert to signed seconds and microseconds for the Unix