From a8d5378a88547fd0158fb12b12adc61c703e2a7d Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 28 Aug 2023 21:21:06 +0800 Subject: [PATCH] logind: add missing asserts --- src/login/logind-session.c | 8 ++++++++ src/login/logind.c | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 4d1caee4d37..939a728a828 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -1293,6 +1293,8 @@ int session_kill(Session *s, KillWho who, int signo) { static int session_open_vt(Session *s) { char path[sizeof("/dev/tty") + DECIMAL_STR_MAX(s->vtnr)]; + assert(s); + if (s->vtnr < 1) return -ENODEV; @@ -1311,6 +1313,8 @@ static int session_prepare_vt(Session *s) { int vt, r; struct vt_mode mode = {}; + assert(s); + if (s->vtnr < 1) return 0; @@ -1366,6 +1370,8 @@ error: static void session_restore_vt(Session *s) { int r; + assert(s); + if (s->vtfd < 0) return; @@ -1444,6 +1450,8 @@ static void session_release_controller(Session *s, bool notify) { _unused_ _cleanup_free_ char *name = NULL; SessionDevice *sd; + assert(s); + if (!s->controller) return; diff --git a/src/login/logind.c b/src/login/logind.c index 79cab940210..0e85bffe2bd 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -438,6 +438,8 @@ static int manager_attach_fds(Manager *m) { /* Upon restart, PID1 will send us back all fds of session devices that we previously opened. Each * file descriptor is associated with a given session. The session ids are passed through FDNAMES. */ + assert(m); + n = sd_listen_fds_with_names(true, &fdnames); if (n < 0) return log_warning_errno(n, "Failed to acquire passed fd list: %m"); @@ -668,7 +670,7 @@ static int manager_connect_bus(Manager *m) { } static int manager_vt_switch(sd_event_source *src, const struct signalfd_siginfo *si, void *data) { - Manager *m = data; + Manager *m = ASSERT_PTR(data); Session *active; /*