From: Lennart Poettering Date: Tue, 10 Sep 2024 13:30:44 +0000 (+0200) Subject: homectl: when chainloading a shell, prefix "-" rather than overriding first char X-Git-Tag: v257-rc1~496 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34ed064f67345f24114f27b8d5b83b6ccf6f3d46;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/home/homectl.c b/src/home/homectl.c index cbb1c79f408..83deeac1238 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)