From a170b35aec47be799af74351f76f0bb0b02d00b7 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 4 Feb 2020 18:56:28 +0200 Subject: [PATCH] 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. --- src/lib/ioloop.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; } -- 2.47.3