From 123e976f3d012b310ac223a54b7ef5213107e33d Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 4 Nov 2021 12:14:02 +0200 Subject: [PATCH] uloop: restore return type of uloop_timeout_remaining The uloop_timeout_remaining function is public and changing its return type breaks ABI. Change the return type back to int, and return INT_MIN or INT_MAX if the value returned by tv_diff would overflow integer. Fixes: be3dc7223a6d ("uloop: avoid integer overflow in tv_diff") Signed-off-by: Stijn Tintel Acked-by: Jo-Philipp Wich Acked-by: John Crispin --- uloop.c | 13 +++++++++++-- uloop.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/uloop.c b/uloop.c index 2972727..769b6c5 100644 --- a/uloop.c +++ b/uloop.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "uloop.h" #include "utils.h" @@ -317,8 +318,9 @@ int uloop_timeout_cancel(struct uloop_timeout *timeout) return 0; } -int64_t uloop_timeout_remaining(struct uloop_timeout *timeout) +int uloop_timeout_remaining(struct uloop_timeout *timeout) { + int64_t td; struct timeval now; if (!timeout->pending) @@ -326,7 +328,14 @@ int64_t uloop_timeout_remaining(struct uloop_timeout *timeout) uloop_gettime(&now); - return tv_diff(&timeout->time, &now); + td = tv_diff(&timeout->time, &now); + + if (td > INT_MAX) + return INT_MAX; + else if (td < INT_MIN) + return INT_MIN; + else + return (int)td; } int uloop_process_add(struct uloop_process *p) diff --git a/uloop.h b/uloop.h index ab6149f..36084f5 100644 --- a/uloop.h +++ b/uloop.h @@ -92,7 +92,7 @@ int uloop_fd_delete(struct uloop_fd *sock); int uloop_timeout_add(struct uloop_timeout *timeout); int uloop_timeout_set(struct uloop_timeout *timeout, int msecs); int uloop_timeout_cancel(struct uloop_timeout *timeout); -int64_t uloop_timeout_remaining(struct uloop_timeout *timeout); +int uloop_timeout_remaining(struct uloop_timeout *timeout); int uloop_process_add(struct uloop_process *p); int uloop_process_delete(struct uloop_process *p);