From 4f097eebd39b3c4da6f92a170e4e58366ab9df32 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 10 Jul 2023 11:06:04 -0600 Subject: [PATCH] libsudo_util: make more bit flags unsigned. --- include/sudo_debug.h | 10 ++++++++++ include/sudo_event.h | 28 ++++++++++++++-------------- lib/util/event.c | 2 +- lib/util/event_poll.c | 2 +- lib/util/event_select.c | 2 +- lib/util/sudo_debug.c | 8 ++++++++ lib/util/util.exp.in | 1 + 7 files changed, 36 insertions(+), 17 deletions(-) diff --git a/include/sudo_debug.h b/include/sudo_debug.h index dbfa57b46..a2e826e52 100644 --- a/include/sudo_debug.h +++ b/include/sudo_debug.h @@ -136,6 +136,14 @@ struct sudo_conf_debug_file_list; return sudo_debug_ret; \ } while (0) +#define debug_return_uint(ret) \ + do { \ + unsigned int sudo_debug_ret = (ret); \ + sudo_debug_exit_uint(__func__, __FILE__, __LINE__, sudo_debug_subsys, \ + sudo_debug_ret); \ + return sudo_debug_ret; \ + } while (0) + #define debug_return_id_t(ret) \ do { \ id_t sudo_debug_ret = (ret); \ @@ -260,6 +268,7 @@ sudo_dso_public void sudo_debug_execve2_v1(unsigned int level, const char *path, sudo_dso_public void sudo_debug_exit_v1(const char *func, const char *file, int line, unsigned int subsys); sudo_dso_public void sudo_debug_exit_bool_v1(const char *func, const char *file, int line, unsigned int subsys, bool ret); sudo_dso_public void sudo_debug_exit_int_v1(const char *func, const char *file, int line, unsigned int subsys, int ret); +sudo_dso_public void sudo_debug_exit_uint_v1(const char *func, const char *file, int line, unsigned int subsys, unsigned int ret); sudo_dso_public void sudo_debug_exit_long_v1(const char *func, const char *file, int line, unsigned int subsys, long ret); sudo_dso_public void sudo_debug_exit_ptr_v1(const char *func, const char *file, int line, unsigned int subsys, const void *ret); sudo_dso_public void sudo_debug_exit_id_t_v1(const char *func, const char *file, int line, unsigned int subsys, id_t ret); @@ -291,6 +300,7 @@ sudo_dso_public bool sudo_debug_needed_v1(unsigned int level); #define sudo_debug_exit(_a, _b, _c, _d) sudo_debug_exit_v1((_a), (_b), (_c), (_d)) #define sudo_debug_exit_bool(_a, _b, _c, _d, _e) sudo_debug_exit_bool_v1((_a), (_b), (_c), (_d), (_e)) #define sudo_debug_exit_int(_a, _b, _c, _d, _e) sudo_debug_exit_int_v1((_a), (_b), (_c), (_d), (_e)) +#define sudo_debug_exit_uint(_a, _b, _c, _d, _e) sudo_debug_exit_uint_v1((_a), (_b), (_c), (_d), (_e)) #define sudo_debug_exit_long(_a, _b, _c, _d, _e) sudo_debug_exit_long_v1((_a), (_b), (_c), (_d), (_e)) #define sudo_debug_exit_ptr(_a, _b, _c, _d, _e) sudo_debug_exit_ptr_v1((_a), (_b), (_c), (_d), (_e)) #define sudo_debug_exit_id_t(_a, _b, _c, _d, _e) sudo_debug_exit_id_t_v1((_a), (_b), (_c), (_d), (_e)) diff --git a/include/sudo_event.h b/include/sudo_event.h index ceff2123e..ae9423a26 100644 --- a/include/sudo_event.h +++ b/include/sudo_event.h @@ -37,22 +37,22 @@ struct timeval; /* for deprecated APIs */ #define SUDO_EV_MASK (SUDO_EV_READ|SUDO_EV_WRITE|SUDO_EV_PERSIST|SUDO_EV_SIGNAL|SUDO_EV_SIGINFO) /* Event flags (internal) */ -#define SUDO_EVQ_INSERTED 0x01 /* event is on the event queue */ -#define SUDO_EVQ_ACTIVE 0x02 /* event is on the active queue */ -#define SUDO_EVQ_TIMEOUTS 0x04 /* event is on the timeouts queue */ +#define SUDO_EVQ_INSERTED 0x01U /* event is on the event queue */ +#define SUDO_EVQ_ACTIVE 0x02U /* event is on the active queue */ +#define SUDO_EVQ_TIMEOUTS 0x04U /* event is on the timeouts queue */ /* Event loop flags */ -#define SUDO_EVLOOP_ONCE 0x01 /* Only run once through the loop */ -#define SUDO_EVLOOP_NONBLOCK 0x02 /* Do not block in event loop */ +#define SUDO_EVLOOP_ONCE 0x01U /* Only run once through the loop */ +#define SUDO_EVLOOP_NONBLOCK 0x02U /* Do not block in event loop */ /* Event base flags (internal) */ #define SUDO_EVBASE_LOOPONCE SUDO_EVLOOP_ONCE -#define SUDO_EVBASE_LOOPEXIT 0x02 -#define SUDO_EVBASE_LOOPBREAK 0x04 -#define SUDO_EVBASE_LOOPCONT 0x08 -#define SUDO_EVBASE_GOT_EXIT 0x10 -#define SUDO_EVBASE_GOT_BREAK 0x20 -#define SUDO_EVBASE_GOT_MASK 0xf0 +#define SUDO_EVBASE_LOOPEXIT 0x02U +#define SUDO_EVBASE_LOOPBREAK 0x04U +#define SUDO_EVBASE_LOOPCONT 0x08U +#define SUDO_EVBASE_GOT_EXIT 0x10U +#define SUDO_EVBASE_GOT_BREAK 0x20U +#define SUDO_EVBASE_GOT_MASK 0xf0U /* Must match sudo_plugin_ev_callback_t in sudo_plugin.h */ typedef void (*sudo_ev_callback_t)(int fd, int what, void *closure); @@ -76,7 +76,7 @@ struct sudo_event { int fd; /* fd/signal we are interested in */ short events; /* SUDO_EV_* flags (in) */ short revents; /* SUDO_EV_* flags (out) */ - short flags; /* internal event flags */ + unsigned short flags; /* internal event flags */ short pfd_idx; /* index into pfds array (XXX) */ sudo_ev_callback_t callback;/* user-provided callback */ struct timespec timeout; /* for SUDO_EV_TIMEOUT */ @@ -150,7 +150,7 @@ sudo_dso_public int sudo_ev_dispatch_v1(struct sudo_event_base *head); #define sudo_ev_dispatch(_a) sudo_ev_dispatch_v1((_a)) /* Main event loop, returns SUDO_CB_SUCCESS, SUDO_CB_BREAK or SUDO_CB_ERROR */ -sudo_dso_public int sudo_ev_loop_v1(struct sudo_event_base *head, int flags); +sudo_dso_public int sudo_ev_loop_v1(struct sudo_event_base *head, unsigned int flags); #define sudo_ev_loop(_a, _b) sudo_ev_loop_v1((_a), (_b)) /* Return pending event types, fills in ts if non-NULL and there is a timeout */ @@ -208,6 +208,6 @@ int sudo_ev_base_alloc_impl(struct sudo_event_base *base); void sudo_ev_base_free_impl(struct sudo_event_base *base); int sudo_ev_add_impl(struct sudo_event_base *base, struct sudo_event *ev); int sudo_ev_del_impl(struct sudo_event_base *base, struct sudo_event *ev); -int sudo_ev_scan_impl(struct sudo_event_base *base, int flags); +int sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags); #endif /* SUDO_EVENT_H */ diff --git a/lib/util/event.c b/lib/util/event.c index 728be2c66..86313d728 100644 --- a/lib/util/event.c +++ b/lib/util/event.c @@ -627,7 +627,7 @@ sudo_ev_dispatch_v1(struct sudo_event_base *base) * Returns 0 on success, 1 if no events registered and -1 on error */ int -sudo_ev_loop_v1(struct sudo_event_base *base, int flags) +sudo_ev_loop_v1(struct sudo_event_base *base, unsigned int flags) { struct timespec now; struct sudo_event *ev; diff --git a/lib/util/event_poll.c b/lib/util/event_poll.c index 029fdf826..4490e9537 100644 --- a/lib/util/event_poll.c +++ b/lib/util/event_poll.c @@ -178,7 +178,7 @@ sudo_ev_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timo) #endif /* HAVE_PPOLL */ int -sudo_ev_scan_impl(struct sudo_event_base *base, int flags) +sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags) { struct timespec now, ts, *timeout; struct sudo_event *ev; diff --git a/lib/util/event_select.c b/lib/util/event_select.c index 8d3e8a9b2..d7966ad4a 100644 --- a/lib/util/event_select.c +++ b/lib/util/event_select.c @@ -185,7 +185,7 @@ sudo_ev_select(int nfds, fd_set *readfds, fd_set *writefds, #endif /* HAVE_PSELECT */ int -sudo_ev_scan_impl(struct sudo_event_base *base, int flags) +sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags) { struct timespec now, ts, *timeout; struct sudo_event *ev; diff --git a/lib/util/sudo_debug.c b/lib/util/sudo_debug.c index 672c0939d..e08461474 100644 --- a/lib/util/sudo_debug.c +++ b/lib/util/sudo_debug.c @@ -519,6 +519,14 @@ sudo_debug_exit_int_v1(const char *func, const char *file, int line, "<- %s @ %s:%d := %d", func, file, line, ret); } +void +sudo_debug_exit_uint_v1(const char *func, const char *file, int line, + unsigned int subsys, unsigned int ret) +{ + sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, + "<- %s @ %s:%d := %u", func, file, line, ret); +} + void sudo_debug_exit_long_v1(const char *func, const char *file, int line, unsigned int subsys, long ret) diff --git a/lib/util/util.exp.in b/lib/util/util.exp.in index 74f081b9a..69df69fc6 100644 --- a/lib/util/util.exp.in +++ b/lib/util/util.exp.in @@ -31,6 +31,7 @@ sudo_debug_exit_ssize_t_v1 sudo_debug_exit_str_masked_v1 sudo_debug_exit_str_v1 sudo_debug_exit_time_t_v1 +sudo_debug_exit_uint_v1 sudo_debug_exit_v1 sudo_debug_fork_v1 sudo_debug_get_active_instance_v1