From: Timo Sirainen Date: Tue, 4 Feb 2020 16:56:28 +0000 (+0200) Subject: lib: Timeouts may have been run a bit too early X-Git-Tag: 2.3.10~95 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a170b35aec47be799af74351f76f0bb0b02d00b7;p=thirdparty%2Fdovecot%2Fcore.git lib: Timeouts may have been run a bit too early 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. --- diff --git a/src/lib/ioloop.c b/src/lib/ioloop.c index 84e415e532..84b3feb228 100644 --- a/src/lib/ioloop.c +++ b/src/lib/ioloop.c @@ -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; }