From 0b5461d5ffadf1e00126555ff9af5c117bb5b130 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 16 Nov 2026 15:08:43 +0100 Subject: [PATCH] Fix NULL pointer dereference in uev_timer_init() uev_timer_init() crashes when called without a watcher: uev_timer_init(ctx, NULL, cb, NULL, 100, 0); The cleanup after a failed setup resets the descriptor in the watcher without checking that there is one. Check the arguments first, like the other watcher types do. Signed-off-by: Joachim Wiberg --- src/timer.c | 5 +++++ test/error.c | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/timer.c b/src/timer.c index 7b07a48..410d36d 100644 --- a/src/timer.c +++ b/src/timer.c @@ -78,6 +78,11 @@ int uev_timer_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeou { int fd; + if (!w || !ctx) { + errno = EINVAL; + return -1; + } + if (timeout < 0 || period < 0) { errno = ERANGE; return -1; diff --git a/test/error.c b/test/error.c index f378b91..1aae319 100644 --- a/test/error.c +++ b/test/error.c @@ -41,9 +41,20 @@ static void ctx_init(void) fail_unless(ctx.fd == -1); } +/* Invalid arguments must not crash */ +static void null_init(void) +{ + uev_ctx_t ctx; + + fail_unless(uev_init(&ctx) == 0); + fail_unless(uev_timer_init(&ctx, NULL, NULL, NULL, 100, 0) != 0); + fail_unless(uev_exit(&ctx) == 0); +} + int main(void) { event_init(); + null_init(); ctx_init(); return 0;