commit a570a80ed1606bed43118cb148fc83c3ac22b5c1
Author:     Roberto E. Vargas Caballero <k...@shike2.com>
AuthorDate: Thu Mar 7 22:35:31 2024 +0100
Commit:     Roberto E. Vargas Caballero <k...@shike2.com>
CommitDate: Thu Mar 7 22:35:31 2024 +0100

    su: Fix running it without arguments
    The commit 8f5a0c3 introduced a regression and the logic
    to control the number of arguments was broken after it,
    giving an error when su was executed without parameters.

diff --git a/su.c b/su.c
index eb8bea7..161d2ec 100644
--- a/su.c
+++ b/su.c
@@ -26,7 +26,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
-       char *usr = "root", *pass;
+       char *usr, *pass;
        char *shell, *envshell, *term;
        struct passwd *pw;
        char *newargv[3];
@@ -43,9 +43,9 @@ main(int argc, char *argv[])
                usage();
        } ARGEND;
 
-       if (argc != 1)
+       if (argc > 1)
                usage();
-       usr = argv[0];
+       usr = argc > 0 ? argv[0] : "root";
 
        errno = 0;
        pw = getpwnam(usr);

Reply via email to