From e3d40ef0105c22f582c8e764e43aab60b016fc26 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 17 Jun 2016 13:45:11 +0200 Subject: [PATCH] Check timer period and timeout arguments The uev_timer_init() and uev_timer_set() functions allow timeout and period to be set < 0, which is not supported. This patch adds a very simple range check. Signed-off-by: Joachim Nilsson --- timer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/timer.c b/timer.c index 8de9bf2..2a06466 100644 --- a/timer.c +++ b/timer.c @@ -67,6 +67,11 @@ int uev_timer_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeou { int fd; + if (timeout < 0 || period < 0) { + errno = ERANGE; + return -1; + } + fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); if (fd < 0) return -1; @@ -100,6 +105,11 @@ int uev_timer_set(uev_t *w, int timeout, int period) return -1; } + if (timeout < 0 || period < 0) { + errno = ERANGE; + return -1; + } + /* Handle stopped timers */ if (w->fd < 0) { /* Timer already stopped */