2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-28 21:07:55 +00:00

Avoid potential use after free with eventlog-only connections.

Coverity CID 215884.
This commit is contained in:
Todd C. Miller 2021-01-02 10:43:34 -07:00
parent 8617833385
commit f6452c7caf

View File

@ -735,7 +735,7 @@ shutdown_cb(int unused, int what, void *v)
static void static void
server_shutdown(struct sudo_event_base *base) server_shutdown(struct sudo_event_base *base)
{ {
struct connection_closure *closure; struct connection_closure *closure, *next;
struct sudo_event *ev; struct sudo_event *ev;
struct timespec tv = { 0, 0 }; struct timespec tv = { 0, 0 };
debug_decl(server_shutdown, SUDO_DEBUG_UTIL); debug_decl(server_shutdown, SUDO_DEBUG_UTIL);
@ -745,7 +745,7 @@ server_shutdown(struct sudo_event_base *base)
debug_return; debug_return;
} }
TAILQ_FOREACH(closure, &connections, entries) { TAILQ_FOREACH_SAFE(closure, &connections, entries, next) {
closure->state = SHUTDOWN; closure->state = SHUTDOWN;
sudo_ev_del(base, closure->read_ev); sudo_ev_del(base, closure->read_ev);
if (closure->log_io) { if (closure->log_io) {
@ -761,13 +761,15 @@ server_shutdown(struct sudo_event_base *base)
} }
} }
/* We need a timed event to exit even if clients time out. */ if (!TAILQ_EMPTY(&connections)) {
ev = sudo_ev_alloc(-1, SUDO_EV_TIMEOUT, shutdown_cb, base); /* We need a timed event to exit even if clients time out. */
if (ev != NULL) { ev = sudo_ev_alloc(-1, SUDO_EV_TIMEOUT, shutdown_cb, base);
tv.tv_sec = SHUTDOWN_TIMEO; if (ev != NULL) {
if (sudo_ev_add(base, ev, &tv, false) == -1) { tv.tv_sec = SHUTDOWN_TIMEO;
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, if (sudo_ev_add(base, ev, &tv, false) == -1) {
"unable to add shutdown event"); sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to add shutdown event");
}
} }
} }