From d3f04a6fa541280a8a205a3d4d2313a043b7a32d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 2 Jul 2025 16:25:00 +0200 Subject: [PATCH 1/2] logind: use memdup_suffix0() where appropiate memdup_suffix0() is the call of choice when we are dealing with an input that might not be NUL terminated. strndup() assumes NUL termination. --- src/login/logind-utmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index 8305ae743f..8f6914f725 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -43,7 +43,7 @@ int manager_read_utmp(Manager *m) { if (!pid_is_valid(u->ut_pid)) continue; - t = strndup(u->ut_line, sizeof(u->ut_line)); + t = memdup_suffix0(u->ut_line, sizeof(u->ut_line)); if (!t) return log_oom(); From bd578c2d66286a874c1bddf6ea7203e38fa16fa9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 2 Jul 2025 16:25:42 +0200 Subject: [PATCH 2/2] logind: pick up tty info from utmp only for tty sessions Let's tighten the rules for picking up TTY information from utmp: let's do so only for TTY session, nothing else. Apparently people have issues with graphical sessions with certain terminal emulators that install entries in utmp for each emulator window. Alternative for: #38027 --- src/login/logind-utmp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index 8f6914f725..26ebb35c64 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -59,6 +59,9 @@ int manager_read_utmp(Manager *m) { if (manager_get_session_by_pidref(m, &PIDREF_MAKE_FROM_PID(u->ut_pid), &s) <= 0) continue; + if (s->type != SESSION_TTY) + continue; + if (s->tty_validity == TTY_FROM_UTMP && !streq_ptr(s->tty, t)) { /* This may happen on multiplexed SSH connection (i.e. 'SSH connection sharing'). In * this case PAM and utmp sessions don't match. In such a case let's invalidate the TTY