Piotr Caban : server: Don't overflow if timeout doesn't fit into int range in get_next_timeout.
Module: wine Branch: master Commit: 3541deb0c3a64d3474a96728d259907180fd7cf6 URL: https://source.winehq.org/git/wine.git/?a=commit;h=3541deb0c3a64d3474a96728d... Author: Piotr Caban <piotr(a)codeweavers.com> Date: Sun Sep 20 15:59:52 2020 +0200 server: Don't overflow if timeout doesn't fit into int range in get_next_timeout. Signed-off-by: Piotr Caban <piotr(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- server/fd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/fd.c b/server/fd.c index a88ba39ef0..59db13bae5 100644 --- a/server/fd.c +++ b/server/fd.c @@ -953,16 +953,18 @@ static int get_next_timeout(void) if ((ptr = list_head( &abs_timeout_list )) != NULL) { struct timeout_user *timeout = LIST_ENTRY( ptr, struct timeout_user, entry ); - int diff = (timeout->when - current_time + 9999) / 10000; - if (diff < 0) diff = 0; + timeout_t diff = (timeout->when - current_time + 9999) / 10000; + if (diff > INT_MAX) diff = INT_MAX; + else if (diff < 0) diff = 0; if (ret == -1 || diff < ret) ret = diff; } if ((ptr = list_head( &rel_timeout_list )) != NULL) { struct timeout_user *timeout = LIST_ENTRY( ptr, struct timeout_user, entry ); - int diff = (-timeout->when - monotonic_time + 9999) / 10000; - if (diff < 0) diff = 0; + timeout_t diff = (-timeout->when - monotonic_time + 9999) / 10000; + if (diff > INT_MAX) diff = INT_MAX; + else if (diff < 0) diff = 0; if (ret == -1 || diff < ret) ret = diff; } }
participants (1)
-
Alexandre Julliard