diff options
author | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2014-10-15 19:42:20 +0200 |
---|---|---|
committer | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2014-10-15 19:42:20 +0200 |
commit | f9fb620914f7b1e2580a890f23b66e18762788b7 (patch) | |
tree | a55b85c9120d5c49466e247d5358bfcba17f1df9 | |
parent | 86633ada91d1c7d8be1bf0398caff8a62fb1b805 (diff) | |
download | st-f9fb620914f7b1e2580a890f23b66e18762788b7.tar.gz st-f9fb620914f7b1e2580a890f23b66e18762788b7.zip |
Do not set SHELL to utmp ever
SHELL must be set to the SHELL of the user, but it was possible set
it to utmp.
-rw-r--r-- | st.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -1146,7 +1146,7 @@ die(const char *errstr, ...) { | |||
1146 | 1146 | ||
1147 | void | 1147 | void |
1148 | execsh(void) { | 1148 | execsh(void) { |
1149 | char **args, *sh; | 1149 | char **args, *sh, *prog; |
1150 | const struct passwd *pw; | 1150 | const struct passwd *pw; |
1151 | char buf[sizeof(long) * 8 + 1]; | 1151 | char buf[sizeof(long) * 8 + 1]; |
1152 | 1152 | ||
@@ -1158,13 +1158,15 @@ execsh(void) { | |||
1158 | die("who are you?\n"); | 1158 | die("who are you?\n"); |
1159 | } | 1159 | } |
1160 | 1160 | ||
1161 | if (utmp) | 1161 | sh = (pw->pw_shell[0]) ? pw->pw_shell : shell; |
1162 | sh = utmp; | 1162 | if(opt_cmd) |
1163 | else if (pw->pw_shell[0]) | 1163 | prog = opt_cmd[0]; |
1164 | sh = pw->pw_shell; | 1164 | else if(utmp) |
1165 | prog = utmp; | ||
1165 | else | 1166 | else |
1166 | sh = shell; | 1167 | prog = sh; |
1167 | args = (opt_cmd) ? opt_cmd : (char *[]){sh, NULL}; | 1168 | args = (opt_cmd) ? opt_cmd : (char *[]) {prog, NULL}; |
1169 | |||
1168 | snprintf(buf, sizeof(buf), "%lu", xw.win); | 1170 | snprintf(buf, sizeof(buf), "%lu", xw.win); |
1169 | 1171 | ||
1170 | unsetenv("COLUMNS"); | 1172 | unsetenv("COLUMNS"); |
@@ -1172,7 +1174,7 @@ execsh(void) { | |||
1172 | unsetenv("TERMCAP"); | 1174 | unsetenv("TERMCAP"); |
1173 | setenv("LOGNAME", pw->pw_name, 1); | 1175 | setenv("LOGNAME", pw->pw_name, 1); |
1174 | setenv("USER", pw->pw_name, 1); | 1176 | setenv("USER", pw->pw_name, 1); |
1175 | setenv("SHELL", args[0], 1); | 1177 | setenv("SHELL", sh, 1); |
1176 | setenv("HOME", pw->pw_dir, 1); | 1178 | setenv("HOME", pw->pw_dir, 1); |
1177 | setenv("TERM", termname, 1); | 1179 | setenv("TERM", termname, 1); |
1178 | setenv("WINDOWID", buf, 1); | 1180 | setenv("WINDOWID", buf, 1); |
@@ -1184,7 +1186,7 @@ execsh(void) { | |||
1184 | signal(SIGTERM, SIG_DFL); | 1186 | signal(SIGTERM, SIG_DFL); |
1185 | signal(SIGALRM, SIG_DFL); | 1187 | signal(SIGALRM, SIG_DFL); |
1186 | 1188 | ||
1187 | execvp(args[0], args); | 1189 | execvp(prog, args); |
1188 | exit(EXIT_FAILURE); | 1190 | exit(EXIT_FAILURE); |
1189 | } | 1191 | } |
1190 | 1192 | ||