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.
This commit is contained in:
Roberto E. Vargas Caballero 2024-03-07 22:35:31 +01:00
parent 4cd0b14380
commit a570a80ed1
1 changed files with 3 additions and 3 deletions

6
su.c
View File

@ -26,7 +26,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *usr = "root", *pass; char *usr, *pass;
char *shell, *envshell, *term; char *shell, *envshell, *term;
struct passwd *pw; struct passwd *pw;
char *newargv[3]; char *newargv[3];
@ -43,9 +43,9 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc != 1) if (argc > 1)
usage(); usage();
usr = argv[0]; usr = argc > 0 ? argv[0] : "root";
errno = 0; errno = 0;
pw = getpwnam(usr); pw = getpwnam(usr);