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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-16 15:08:43 +01:00
1 parent 397247d567
commit 0b5461d5ff
2 files changed
+16

No files matched your search

+5
View File
@@ -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;
+11
View File
@@ -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;