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: be3dc7223a ("uloop: avoid integer overflow in tv_diff")
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Acked-by: Jo-Philipp Wich <jo@mein.io>
Acked-by: John Crispin <john@phrozen.org>
This commit is contained in:
Stijn Tintel 2021-11-04 12:14:02 +02:00
parent be3dc7223a
commit 123e976f3d
2 changed files with 12 additions and 3 deletions

13
uloop.c
View file

@ -26,6 +26,7 @@
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdbool.h> #include <stdbool.h>
#include <limits.h>
#include "uloop.h" #include "uloop.h"
#include "utils.h" #include "utils.h"
@ -317,8 +318,9 @@ int uloop_timeout_cancel(struct uloop_timeout *timeout)
return 0; 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; struct timeval now;
if (!timeout->pending) if (!timeout->pending)
@ -326,7 +328,14 @@ int64_t uloop_timeout_remaining(struct uloop_timeout *timeout)
uloop_gettime(&now); 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) int uloop_process_add(struct uloop_process *p)

View file

@ -92,7 +92,7 @@ int uloop_fd_delete(struct uloop_fd *sock);
int uloop_timeout_add(struct uloop_timeout *timeout); int uloop_timeout_add(struct uloop_timeout *timeout);
int uloop_timeout_set(struct uloop_timeout *timeout, int msecs); int uloop_timeout_set(struct uloop_timeout *timeout, int msecs);
int uloop_timeout_cancel(struct uloop_timeout *timeout); 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_add(struct uloop_process *p);
int uloop_process_delete(struct uloop_process *p); int uloop_process_delete(struct uloop_process *p);