From bfb16896221924b6cf17340aace45db0cc610497 Mon Sep 17 00:00:00 2001 From: iefa m Date: Sat, 21 Nov 2026 14:53:48 +0530 Subject: [PATCH] sudo_ev_add_impl: store the poll slot index as an int The pollfd array in the event base can grow to RLIMIT_NOFILE entries, but each event remembers its slot in a short. Once more than 32767 I/O events are registered, slot 32768 is stored as -32768 and the event's fd and events are written 256 KiB before the start of the array, with later deletes and scans using the same bad slot. sudo_logsrvd raises RLIMIT_NOFILE to the hard limit and keeps a read event for every client connection, so enough idle connections are sufficient to reach this. Use an int, like pfd_free, pfd_max and pfd_high. --- include/sudo_event.h | 2 +- lib/util/event_poll.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/sudo_event.h b/include/sudo_event.h index 27985c486e..dd5ca545e0 100644 --- a/include/sudo_event.h +++ b/include/sudo_event.h @@ -77,7 +77,7 @@ struct sudo_event { short events; /* SUDO_EV_* flags (in) */ short revents; /* SUDO_EV_* flags (out) */ unsigned short flags; /* internal event flags */ - short pfd_idx; /* index into pfds array (XXX) */ + int pfd_idx; /* index into pfds array */ sudo_ev_callback_t callback;/* user-provided callback */ struct timespec timeout; /* for SUDO_EV_TIMEOUT */ void *closure; /* user-provided data pointer */ diff --git a/lib/util/event_poll.c b/lib/util/event_poll.c index f61de491d2..9357b00f20 100644 --- a/lib/util/event_poll.c +++ b/lib/util/event_poll.c @@ -115,7 +115,7 @@ sudo_ev_add_impl(struct sudo_event_base *base, struct sudo_event *ev) /* Fill in pfd entry. */ sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO, "%s: choosing free slot %d", __func__, base->pfd_free); - ev->pfd_idx = (short)base->pfd_free; + ev->pfd_idx = base->pfd_free; pfd = &base->pfds[ev->pfd_idx]; pfd->fd = ev->fd; pfd->events = 0;