summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorSami Kerola2016-08-07 08:27:21 +0200
committerSami Kerola2016-08-12 22:25:36 +0200
commit984a60965a0e3cd3253a74c77af916b05381c03d (patch)
tree8aafe4e47b256298b2ed294dbdcdc50c59c730bf /login-utils
parenttests: mark build-in paths test as optional (diff)
downloadkernel-qcow2-util-linux-984a60965a0e3cd3253a74c77af916b05381c03d.tar.gz
kernel-qcow2-util-linux-984a60965a0e3cd3253a74c77af916b05381c03d.tar.xz
kernel-qcow2-util-linux-984a60965a0e3cd3253a74c77af916b05381c03d.zip
misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/login.c19
-rw-r--r--login-utils/su-common.c2
-rw-r--r--login-utils/sulogin.c21
3 files changed, 23 insertions, 19 deletions
diff --git a/login-utils/login.c b/login-utils/login.c
index 7501f6d69..1de24a8b8 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -69,6 +69,7 @@
#include "pathnames.h"
#include "strutils.h"
#include "nls.h"
+#include "env.h"
#include "xalloc.h"
#include "all-io.h"
#include "fileutils.h"
@@ -1040,27 +1041,29 @@ static void init_environ(struct login_context *cxt)
memset(environ, 0, sizeof(char *));
}
- setenv("HOME", pwd->pw_dir, 0); /* legal to override */
- setenv("USER", pwd->pw_name, 1);
- setenv("SHELL", pwd->pw_shell, 1);
- setenv("TERM", termenv ? termenv : "dumb", 1);
+ xsetenv("HOME", pwd->pw_dir, 0); /* legal to override */
+ xsetenv("USER", pwd->pw_name, 1);
+ xsetenv("SHELL", pwd->pw_shell, 1);
+ xsetenv("TERM", termenv ? termenv : "dumb", 1);
free(termenv);
if (pwd->pw_uid)
- logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH);
+ if (logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH) != 0)
+ err(EXIT_FAILURE, _("failed to set the %s environment variable"), "PATH");
else if (logindefs_setenv("PATH", "ENV_ROOTPATH", NULL) != 0)
- logindefs_setenv("PATH", "ENV_SUPATH", _PATH_DEFPATH_ROOT);
+ if (logindefs_setenv("PATH", "ENV_SUPATH", _PATH_DEFPATH_ROOT) != 0)
+ err(EXIT_FAILURE, _("failed to set the %s environment variable"), "PATH");
/* mailx will give a funny error msg if you forget this one */
len = snprintf(tmp, sizeof(tmp), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
if (len > 0 && (size_t) len < sizeof(tmp))
- setenv("MAIL", tmp, 0);
+ xsetenv("MAIL", tmp, 0);
/* LOGNAME is not documented in login(1) but HP-UX 6.5 does it. We'll
* not allow modifying it.
*/
- setenv("LOGNAME", pwd->pw_name, 1);
+ xsetenv("LOGNAME", pwd->pw_name, 1);
env = pam_getenvlist(cxt->pamh);
for (i = 0; env && env[i]; i++)
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index 1776b6b79..ff20a2f47 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -520,7 +520,7 @@ set_path(const struct passwd* pw)
r = logindefs_setenv("PATH", "ENV_SUPATH", _PATH_DEFPATH_ROOT);
if (r != 0)
- err (EXIT_FAILURE, _("failed to set PATH"));
+ err (EXIT_FAILURE, _("failed to set the %s environment variable"), "PATH");
}
/* Update `environ' for the new shell based on PW, with SHELL being
diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
index fdbda7c87..1c4313af4 100644
--- a/login-utils/sulogin.c
+++ b/login-utils/sulogin.c
@@ -56,6 +56,7 @@
#include "c.h"
#include "closestream.h"
+#include "env.h"
#include "nls.h"
#include "pathnames.h"
#ifdef USE_PLYMOUTH_SUPPORT
@@ -219,18 +220,18 @@ static void tcfinal(struct console *con)
int fd;
if ((con->flags & CON_SERIAL) == 0) {
- setenv("TERM", "linux", 1);
+ xsetenv("TERM", "linux", 1);
return;
}
if (con->flags & CON_NOTTY) {
- setenv("TERM", "dumb", 1);
+ xsetenv("TERM", "dumb", 1);
return;
}
#if defined (__s390__) || defined (__s390x__)
- setenv("TERM", "dumb", 1);
+ xsetenv("TERM", "dumb", 1);
#else
- setenv("TERM", "vt102", 1);
+ xsetenv("TERM", "vt102", 1);
#endif
tio = &con->tio;
fd = con->fd;
@@ -759,16 +760,16 @@ static void sushell(struct passwd *pwd)
if (getcwd(home, sizeof(home)) == NULL)
strcpy(home, "/");
- setenv("HOME", home, 1);
- setenv("LOGNAME", "root", 1);
- setenv("USER", "root", 1);
+ xsetenv("HOME", home, 1);
+ xsetenv("LOGNAME", "root", 1);
+ xsetenv("USER", "root", 1);
if (!profile)
- setenv("SHLVL","0",1);
+ xsetenv("SHLVL","0",1);
/*
* Try to execute a shell.
*/
- setenv("SHELL", su_shell, 1);
+ xsetenv("SHELL", su_shell, 1);
unmask_signal(SIGINT, &saved_sigint);
unmask_signal(SIGTSTP, &saved_sigtstp);
unmask_signal(SIGQUIT, &saved_sigquit);
@@ -793,7 +794,7 @@ static void sushell(struct passwd *pwd)
execl(su_shell, shell, NULL);
warn(_("failed to execute %s"), su_shell);
- setenv("SHELL", "/bin/sh", 1);
+ xsetenv("SHELL", "/bin/sh", 1);
execl("/bin/sh", profile ? "-sh" : "sh", NULL);
warn(_("failed to execute %s"), "/bin/sh");
}