]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homectl: when chainloading a shell, prefix "-" rather than overriding first char
authorLennart Poettering <lennart@poettering.net>
Tue, 10 Sep 2024 13:30:44 +0000 (15:30 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Sep 2024 15:24:21 +0000 (17:24 +0200)
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

index cbb1c79f40886ebf3c31beb572ee7a6aba9a2cd7..83deeac12387b5a8f8a29e86c1e59b79c2303a55 100644 (file)
@@ -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)