]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Timeouts may have been run a bit too early
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 4 Feb 2020 16:56:28 +0000 (18:56 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 6 Feb 2020 07:59:27 +0000 (07:59 +0000)
The timeout was run early if it was to be run in less than 1 millisecond.

This could have resulted in an infinite loop in some special situations
when timeout_add_absolute() was used in a timeout callback.

src/lib/ioloop.c

index 84e415e532eefdb17f8418520d22f5c70724451e..84b3feb2288c7d29dd3e2d2c6bb46542b39554cf 100644 (file)
@@ -463,7 +463,8 @@ static int timeout_get_wait_time(struct timeout *timeout, struct timeval *tv_r,
                tv_r->tv_usec += 1000000;
        }
 
-       if (tv_r->tv_sec < 0 || (tv_r->tv_sec == 0 && tv_r->tv_usec < 1000)) {
+       if (tv_r->tv_sec < 0) {
+               /* The timeout should have been called already */
                tv_r->tv_sec = 0;
                tv_r->tv_usec = 0;
                return 0;
@@ -473,7 +474,7 @@ static int timeout_get_wait_time(struct timeout *timeout, struct timeval *tv_r,
 
        /* round wait times up to next millisecond */
        ret = tv_r->tv_sec * 1000 + (tv_r->tv_usec + 999) / 1000;
-       i_assert(ret > 0 && tv_r->tv_sec >= 0 && tv_r->tv_usec >= 0);
+       i_assert(ret >= 0 && tv_r->tv_sec >= 0 && tv_r->tv_usec >= 0);
        return ret;
 }