[hackers] [ubase][PATCH 2/4] su: fix setting argv0

From: neeshy <neeshy_AT_tfwno.gf>
Date: Mon, 12 Feb 2024 16:25:50 -0500

argv0 was being set to the user's login shell even when -p was
specified. Only populate newargv once the shell is properly determined.
---
 su.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/su.c b/su.c
index bc7a94f..812aa43 100644
--- a/su.c
+++ b/su.c
_AT_@ -76,9 +76,6 @@ main(int argc, char *argv[])
 
 	shell = pw->pw_shell[0] == '\0' ? "/bin/sh" : pw->pw_shell;
 	if (lflag) {
-		newargv[0] = shell;
-		newargv[1] = "-l";
-		newargv[2] = NULL;
 		term = getenv("TERM");
 		clearenv();
 		setenv("HOME", pw->pw_dir, 1);
_AT_@ -88,9 +85,10 @@ main(int argc, char *argv[])
 		setenv("TERM", term ? term : "linux", 1);
 		if (chdir(pw->pw_dir) < 0)
 			eprintf("chdir %s:", pw->pw_dir);
-	} else {
 		newargv[0] = shell;
-		newargv[1] = NULL;
+		newargv[1] = "-l";
+		newargv[2] = NULL;
+	} else {
 		if (pflag) {
 			shell = getenv("SHELL");
 		} else {
_AT_@ -101,6 +99,8 @@ main(int argc, char *argv[])
 				setenv("LOGNAME", pw->pw_name, 1);
 			}
 		}
+		newargv[0] = shell;
+		newargv[1] = NULL;
 	}
 	if (strcmp(pw->pw_name, "root") == 0)
 		setenv("PATH", ENV_SUPATH, 1);
-- 
2.43.0
Received on Mon Feb 12 2024 - 22:25:50 CET

This archive was generated by hypermail 2.3.0 : Mon Feb 12 2024 - 22:36:32 CET