From 34ed064f67345f24114f27b8d5b83b6ccf6f3d46 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 10 Sep 2024 15:30:44 +0200 Subject: [PATCH] homectl: when chainloading a shell, prefix "-" rather than overriding first char Login shells are supposed to marked via a dash as first char. We follow that logic, but right now we simply overwrite the first char of the shell. That might not be the right choice, given that this turns "zsh" into "-sh", which suggests some bourne shell process. Hence, let's correct things, and instead prefix a dash, which should be safer. Inspired by findings on https://github.com/systemd/systemd/issues/34153#issuecomment-2338104907 --- src/home/homectl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/home/homectl.c b/src/home/homectl.c index cbb1c79f40..83deeac123 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -4538,8 +4538,13 @@ static int fallback_shell(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EISDIR), "Shell '%s' is a path to a directory, refusing.", shell); /* Invoke this as login shell, by setting argv[0][0] to '-' (unless we ourselves weren't called as login shell) */ - if (!argv || isempty(argv[0]) || argv[0][0] == '-') - argv0[0] = '-'; + if (!argv || isempty(argv[0]) || argv[0][0] == '-') { + _cleanup_free_ char *prefixed = strjoin("-", argv0); + if (!prefixed) + return log_oom(); + + free_and_replace(argv0, prefixed); + } l = strv_new(argv0); if (!l) -- 2.25.1