diff --git a/include/sudo_event.h b/include/sudo_event.h index ae9423a26..d27596d88 100644 --- a/include/sudo_event.h +++ b/include/sudo_event.h @@ -126,7 +126,8 @@ sudo_dso_public void sudo_ev_base_setdef_v1(struct sudo_event_base *base); /* Allocate a new event. */ sudo_dso_public struct sudo_event *sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closure); -#define sudo_ev_alloc(_a, _b, _c, _d) sudo_ev_alloc_v1((_a), (_b), (_c), (_d)) +sudo_dso_public struct sudo_event *sudo_ev_alloc_v2(int fd, int events, sudo_ev_callback_t callback, void *closure); +#define sudo_ev_alloc(_a, _b, _c, _d) sudo_ev_alloc_v2((_a), (_b), (_c), (_d)) /* Free an event. */ sudo_dso_public void sudo_ev_free_v1(struct sudo_event *ev); @@ -134,7 +135,8 @@ sudo_dso_public void sudo_ev_free_v1(struct sudo_event *ev); /* Set an event struct that was pre-allocated. */ sudo_dso_public int sudo_ev_set_v1(struct sudo_event *ev, int fd, short events, sudo_ev_callback_t callback, void *closure); -#define sudo_ev_set(_a, _b, _c, _d, _e) sudo_ev_set_v1((_a), (_b), (_c), (_d), (_e)) +sudo_dso_public int sudo_ev_set_v2(struct sudo_event *ev, int fd, int events, sudo_ev_callback_t callback, void *closure); +#define sudo_ev_set(_a, _b, _c, _d, _e) sudo_ev_set_v2((_a), (_b), (_c), (_d), (_e)) /* Add an event, returns 0 on success, -1 on error */ sudo_dso_public int sudo_ev_add_v1(struct sudo_event_base *head, struct sudo_event *ev, const struct timeval *timo, bool tohead); @@ -155,7 +157,8 @@ sudo_dso_public int sudo_ev_loop_v1(struct sudo_event_base *head, unsigned int f /* Return pending event types, fills in ts if non-NULL and there is a timeout */ sudo_dso_public int sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts); -#define sudo_ev_pending(_a, _b, _c) sudo_ev_pending_v1((_a), (_b), (_c)) +sudo_dso_public int sudo_ev_pending_v2(struct sudo_event *ev, int events, struct timespec *ts); +#define sudo_ev_pending(_a, _b, _c) sudo_ev_pending_v2((_a), (_b), (_c)) /* Return the remaining timeout associated with an event (deprecated). */ sudo_dso_public int sudo_ev_get_timeleft_v1(struct sudo_event *ev, struct timeval *tv); diff --git a/lib/util/event.c b/lib/util/event.c index 86313d728..9228fc2c0 100644 --- a/lib/util/event.c +++ b/lib/util/event.c @@ -44,7 +44,7 @@ #include "sudo_event.h" #include "sudo_util.h" -static void sudo_ev_init(struct sudo_event *ev, int fd, short events, +static void sudo_ev_init(struct sudo_event *ev, int fd, int events, sudo_ev_callback_t callback, void *closure); /* Default event base when none is specified. */ @@ -263,7 +263,7 @@ sudo_ev_base_setdef_v1(struct sudo_event_base *base) * Clear and fill in a struct sudo_event. */ static void -sudo_ev_init(struct sudo_event *ev, int fd, short events, +sudo_ev_init(struct sudo_event *ev, int fd, int events, sudo_ev_callback_t callback, void *closure) { debug_decl(sudo_ev_init, SUDO_DEBUG_EVENT); @@ -283,7 +283,7 @@ sudo_ev_init(struct sudo_event *ev, int fd, short events, * Allocates space for siginfo_t for SUDO_EV_SIGINFO as needed. */ int -sudo_ev_set_v1(struct sudo_event *ev, int fd, short events, +sudo_ev_set_v2(struct sudo_event *ev, int fd, int events, sudo_ev_callback_t callback, void *closure) { debug_decl(sudo_ev_set, SUDO_DEBUG_EVENT); @@ -305,8 +305,15 @@ sudo_ev_set_v1(struct sudo_event *ev, int fd, short events, debug_return_int(0); } +int +sudo_ev_set_v1(struct sudo_event *ev, int fd, short events, + sudo_ev_callback_t callback, void *closure) +{ + return sudo_ev_set_v2(ev, fd, events, callback, closure); +} + struct sudo_event * -sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closure) +sudo_ev_alloc_v2(int fd, int events, sudo_ev_callback_t callback, void *closure) { struct sudo_event *ev; debug_decl(sudo_ev_alloc, SUDO_DEBUG_EVENT); @@ -324,6 +331,12 @@ sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closur debug_return_ptr(ev); } +struct sudo_event * +sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closure) +{ + return sudo_ev_alloc_v2(fd, events, callback, closure); +} + void sudo_ev_free_v1(struct sudo_event *ev) { @@ -833,7 +846,7 @@ sudo_ev_get_timeleft_v2(struct sudo_event *ev, struct timespec *ts) } int -sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts) +sudo_ev_pending_v2(struct sudo_event *ev, int events, struct timespec *ts) { int ret; debug_decl(sudo_ev_pending, SUDO_DEBUG_EVENT); @@ -860,3 +873,9 @@ sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts) debug_return_int(ret); } + +int +sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts) +{ + return sudo_ev_pending_v2(ev, events, ts); +} diff --git a/lib/util/event_poll.c b/lib/util/event_poll.c index 4490e9537..13f2f4d66 100644 --- a/lib/util/event_poll.c +++ b/lib/util/event_poll.c @@ -120,7 +120,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 = base->pfd_free; + ev->pfd_idx = (short)base->pfd_free; pfd = &base->pfds[ev->pfd_idx]; pfd->fd = ev->fd; pfd->events = 0; @@ -226,7 +226,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags) sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: polled fd %d, events %d, activating %p", __func__, ev->fd, what, ev); - ev->revents = what; + ev->revents = (short)what; sudo_ev_activate(base, ev); } } diff --git a/lib/util/event_select.c b/lib/util/event_select.c index d7966ad4a..92803c85a 100644 --- a/lib/util/event_select.c +++ b/lib/util/event_select.c @@ -82,14 +82,14 @@ sudo_ev_add_impl(struct sudo_event_base *base, struct sudo_event *ev) if (ev->fd > base->maxfd) { const int o = (base->maxfd + 1) / NFDBITS; const int n = howmany(ev->fd + 1, NFDBITS); - const size_t used_bytes = o * sizeof(fd_mask); - const size_t new_bytes = (n - o) * sizeof(fd_mask); + const size_t used_bytes = (size_t)o * sizeof(fd_mask); + const size_t new_bytes = (size_t)(n - o) * sizeof(fd_mask); fd_set *rfds_in, *wfds_in, *rfds_out, *wfds_out; - rfds_in = reallocarray(base->readfds_in, n, sizeof(fd_mask)); - wfds_in = reallocarray(base->writefds_in, n, sizeof(fd_mask)); - rfds_out = reallocarray(base->readfds_out, n, sizeof(fd_mask)); - wfds_out = reallocarray(base->writefds_out, n, sizeof(fd_mask)); + rfds_in = reallocarray(base->readfds_in, (size_t)n, sizeof(fd_mask)); + wfds_in = reallocarray(base->writefds_in, (size_t)n, sizeof(fd_mask)); + rfds_out = reallocarray(base->readfds_out, (size_t)n, sizeof(fd_mask)); + wfds_out = reallocarray(base->writefds_out, (size_t)n, sizeof(fd_mask)); if (rfds_in == NULL || wfds_in == NULL || rfds_out == NULL || wfds_out == NULL) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, @@ -209,7 +209,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags) } /* select() overwrites readfds/writefds so make a copy. */ - setsize = howmany(base->highfd + 1, NFDBITS) * sizeof(fd_mask); + setsize = (size_t)howmany(base->highfd + 1, NFDBITS) * sizeof(fd_mask); memcpy(base->readfds_out, base->readfds_in, setsize); memcpy(base->writefds_out, base->writefds_in, setsize); @@ -229,7 +229,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags) /* Activate each I/O event that fired. */ TAILQ_FOREACH(ev, &base->events, entries) { if (ev->fd >= 0) { - int what = 0; + short what = 0; if (FD_ISSET(ev->fd, (fd_set *)base->readfds_out)) what |= (ev->events & SUDO_EV_READ); if (FD_ISSET(ev->fd, (fd_set *)base->writefds_out)) @@ -237,7 +237,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags) if (what != 0) { /* Make event active. */ sudo_debug_printf(SUDO_DEBUG_DEBUG, - "%s: selected fd %d, events %d, activating %p", + "%s: selected fd %d, events %hd, activating %p", __func__, ev->fd, what, ev); ev->revents = what; sudo_ev_activate(base, ev); diff --git a/lib/util/util.exp.in b/lib/util/util.exp.in index 440bc8f8c..90c87e87b 100644 --- a/lib/util/util.exp.in +++ b/lib/util/util.exp.in @@ -61,6 +61,7 @@ sudo_dso_unload_v1 sudo_ev_add_v1 sudo_ev_add_v2 sudo_ev_alloc_v1 +sudo_ev_alloc_v2 sudo_ev_base_alloc_v1 sudo_ev_base_free_v1 sudo_ev_base_setdef_v1 @@ -76,7 +77,9 @@ sudo_ev_loopbreak_v1 sudo_ev_loopcontinue_v1 sudo_ev_loopexit_v1 sudo_ev_pending_v1 +sudo_ev_pending_v2 sudo_ev_set_v1 +sudo_ev_set_v2 sudo_fatal_callback_deregister_v1 sudo_fatal_callback_register_v1 sudo_fatal_nodebug_v1