]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sched: detect timeout overflow in SCH_AddTimeoutByDelay()
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 8 Jun 2015 12:49:52 +0000 (14:49 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 8 Jun 2015 12:49:52 +0000 (14:49 +0200)
Abort when the system time gets so close to the end of 32-bit time_t
that timeouts added by delay start to overflow. This is an addition to
the loop detector in dispatch_timeouts().

sched.c

diff --git a/sched.c b/sched.c
index bee30316b60ab8d965901c5070cc1d0a9f0fb657..1946745c856a003a33f588131b9c39bf37177bcd 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -330,6 +330,10 @@ SCH_AddTimeoutByDelay(double delay, SCH_TimeoutHandler handler, SCH_ArbitraryArg
 
   LCL_ReadRawTime(&now);
   UTI_AddDoubleToTimeval(&now, delay, &then);
+  if (UTI_CompareTimevals(&now, &then) > 0) {
+    LOG_FATAL(LOGF_Scheduler, "Timeout overflow");
+  }
+
   return SCH_AddTimeout(&then, handler, arg);
 
 }