From 6fb88001385c6a4173496adba5c65f94bfa861e0 Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Thu, 12 Jan 2006 13:43:11 +0000 Subject: [PATCH] Check for setenv/putenv's success Submitted-by: Alexey Slynko --- bin/date/date.c | 5 ++-- bin/df/df.c | 14 ++++++---- bin/ls/ls.c | 5 ++-- bin/sh/var.c | 11 +++++--- lib/libutil/login_cap.h | 4 +-- lib/libutil/login_class.3 | 13 ++++++++-- lib/libutil/login_class.c | 49 ++++++++++++++++++++++++++--------- libexec/ftpd/popen.c | 5 ++-- libexec/telnetd/state.c | 17 +++++++----- libexec/telnetd/sys_term.c | 14 ++++++---- libexec/telnetd/telnetd.c | 5 ++-- usr.bin/du/du.c | 8 +++--- usr.bin/env/env.c | 4 +-- usr.bin/fetch/fetch.c | 8 +++--- usr.bin/ldd/ldd.c | 20 +++++++++----- usr.bin/limits/limits.c | 8 +++--- usr.bin/login/login.c | 32 +++++++++++++++-------- usr.bin/objformat/objformat.c | 5 ++-- usr.bin/su/su.c | 29 ++++++++++++++------- usr.bin/tabs/tabs.c | 11 +++++--- usr.bin/whereis/whereis.c | 5 ++-- usr.bin/window/wwenviron.c | 8 +++--- usr.bin/window/wwinit.c | 5 ++-- usr.bin/window/wwterminfo.c | 5 ++-- usr.sbin/cron/cron/cron.c | 8 ++++-- usr.sbin/inetd/inetd.c | 6 +++-- usr.sbin/pstat/pstat.c | 5 ++-- usr.sbin/tzsetup/tzsetup.c | 5 ++-- 28 files changed, 208 insertions(+), 106 deletions(-) diff --git a/bin/date/date.c b/bin/date/date.c index f7680096db..36ff3e97ce 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1985, 1987, 1988, 1993 The Regents of the University of California. All rights reserved. * @(#)date.c 8.2 (Berkeley) 4/28/95 * $FreeBSD: src/bin/date/date.c,v 1.47 2005/01/10 08:39:21 imp Exp $ - * $DragonFly: src/bin/date/date.c,v 1.13 2005/07/20 19:51:56 cpressey Exp $ + * $DragonFly: src/bin/date/date.c,v 1.14 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -117,7 +117,8 @@ main(int argc, char **argv) set_timezone = 1; break; case 'u': /* do everything in UTC */ - setenv("TZ", "UTC0", 1); + if (setenv("TZ", "UTC0", 1) != 0) + err(1, "setenv: cannot set TZ=UTC0"); break; case 'v': v = vary_append(v, optarg); diff --git a/bin/df/df.c b/bin/df/df.c index 9dcc61c4a2..3b5af67eee 100644 --- a/bin/df/df.c +++ b/bin/df/df.c @@ -38,7 +38,7 @@ * @(#) Copyright (c) 1980, 1990, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)df.c 8.9 (Berkeley) 5/8/95 * $FreeBSD: src/bin/df/df.c,v 1.23.2.9 2002/07/01 00:14:24 iedowse Exp $ - * $DragonFly: src/bin/df/df.c,v 1.6 2005/11/06 11:44:02 swildner Exp $ + * $DragonFly: src/bin/df/df.c,v 1.7 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -145,11 +145,13 @@ main(int argc, char **argv) case 'b': /* FALLTHROUGH */ case 'P': - putenv("BLOCKSIZE=512"); + if (putenv("BLOCKSIZE=512") != 0) + warn("putenv: cannot set BLOCKSIZE=512"); hflag = 0; break; case 'g': - putenv("BLOCKSIZE=1g"); + if (putenv("BLOCKSIZE=1g") != 0) + warn("putenv: cannot set BLOCKSIZE=1g"); hflag = 0; break; case 'H': @@ -164,7 +166,8 @@ main(int argc, char **argv) iflag = 1; break; case 'k': - putenv("BLOCKSIZE=1k"); + if (putenv("BLOCKSIZE=1k") != 0) + warn("putenv: cannot set BLOCKSIZE=1k"); hflag = 0; break; case 'l': @@ -173,7 +176,8 @@ main(int argc, char **argv) vfslist = makevfslist(makenetvfslist()); break; case 'm': - putenv("BLOCKSIZE=1m"); + if (putenv("BLOCKSIZE=1m") != 0) + warn("putenv: cannot set BLOCKSIZE=1m"); hflag = 0; break; case 'n': diff --git a/bin/ls/ls.c b/bin/ls/ls.c index b7569dfb19..407dd552ee 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -32,7 +32,7 @@ * @(#) Copyright (c) 1989, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)ls.c 8.5 (Berkeley) 4/2/94 * $FreeBSD: src/bin/ls/ls.c,v 1.78 2004/06/08 09:30:10 das Exp $ - * $DragonFly: src/bin/ls/ls.c,v 1.14 2005/09/18 18:01:49 asmodai Exp $ + * $DragonFly: src/bin/ls/ls.c,v 1.15 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -221,7 +221,8 @@ main(int argc, char *argv[]) fts_options |= FTS_COMFOLLOW; break; case 'G': - setenv("CLICOLOR", "", 1); + if (setenv("CLICOLOR", "", 1) != 0) + warn("setenv: cannot set CLICOLOR"); break; case 'L': fts_options &= ~FTS_PHYSICAL; diff --git a/bin/sh/var.c b/bin/sh/var.c index c76f403bfb..6976bbd561 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -35,7 +35,7 @@ * * @(#)var.c 8.3 (Berkeley) 5/4/95 * $FreeBSD: src/bin/sh/var.c,v 1.15.2.2 2002/08/27 01:36:28 tjr Exp $ - * $DragonFly: src/bin/sh/var.c,v 1.10 2005/12/04 20:32:50 dillon Exp $ + * $DragonFly: src/bin/sh/var.c,v 1.11 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -316,7 +316,8 @@ setvareq(char *s, int flags) if (vp == &vmpath || (vp == &vmail && ! mpathset())) chkmail(1); if ((vp->flags & VEXPORT) && localevar(s)) { - putenv(s); + if (putenv(s) != 0) + error("putenv: cannot set %s", s); setlocale(LC_ALL, ""); } INTON; @@ -332,7 +333,8 @@ setvareq(char *s, int flags) INTOFF; *vpp = vp; if ((vp->flags & VEXPORT) && localevar(s)) { - putenv(s); + if (putenv(s) != 0) + error("putenv: cannot set %s", s); setlocale(LC_ALL, ""); } INTON; @@ -553,7 +555,8 @@ exportcmd(int argc, char **argv) vp->flags |= flag; if ((vp->flags & VEXPORT) && localevar(vp->text)) { - putenv(vp->text); + if (putenv(vp->text) != 0) + error("putenv: cannot set %s", vp->text); setlocale(LC_ALL, ""); } goto found; diff --git a/lib/libutil/login_cap.h b/lib/libutil/login_cap.h index 9933dbbb8d..d8d22a5f62 100644 --- a/lib/libutil/login_cap.h +++ b/lib/libutil/login_cap.h @@ -23,7 +23,7 @@ * * Was login_cap.h,v 1.9 1997/05/07 20:00:01 eivind Exp * $FreeBSD: src/lib/libutil/login_cap.h,v 1.3.2.1 2000/09/20 11:19:54 green Exp $ - * $DragonFly: src/lib/libutil/login_cap.h,v 1.3 2003/11/12 20:21:31 eirikn Exp $ + * $DragonFly: src/lib/libutil/login_cap.h,v 1.4 2006/01/12 13:43:10 corecode Exp $ */ #ifndef _LOGIN_CAP_H_ @@ -116,7 +116,7 @@ const char *login_setcryptfmt (login_cap_t *, const char *, const char *); int setclasscontext (const char*, unsigned int); int setusercontext (login_cap_t*, const struct passwd*, uid_t, unsigned int); void setclassresources (login_cap_t *); -void setclassenvironment (login_cap_t *, const struct passwd *, int); +int setclassenvironment (login_cap_t *, const struct passwd *, int); /* Most of these functions are deprecated */ int auth_approve (login_cap_t*, const char*, const char*); diff --git a/lib/libutil/login_class.3 b/lib/libutil/login_class.3 index 2704dd1a42..e6af8aaa14 100644 --- a/lib/libutil/login_class.3 +++ b/lib/libutil/login_class.3 @@ -18,7 +18,7 @@ .\" conditions are met. .\" .\" $FreeBSD: src/lib/libutil/login_class.3,v 1.9.2.4 2003/04/29 14:40:07 trhodes Exp $ -.\" $DragonFly: src/lib/libutil/login_class.3,v 1.2 2003/06/17 04:26:52 dillon Exp $ +.\" $DragonFly: src/lib/libutil/login_class.3,v 1.3 2006/01/12 13:43:10 corecode Exp $ .\" .Dd December 28, 1996 .Os @@ -40,7 +40,7 @@ .Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags" .Ft void .Fn setclassresources "login_cap_t *lc" -.Ft void +.Ft int .Fn setclassenvironment "login_cap_t *lc" "const struct passwd *pwd" "int paths" .Sh DESCRIPTION These functions provide a higher level interface to the login class @@ -172,6 +172,8 @@ and functions are subsets of the setcontext functions above, but may be useful in isolation. .Sh RETURN VALUES +.Fn setclassenvironment +, .Fn setclasscontext and .Fn setusercontext @@ -180,6 +182,13 @@ If an error occurs when attempting to set the user, login, group or resources, a message is reported to .Xr syslog 3 , with LOG_ERR priority and directed to the currently active facility. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er ENOMEM +The function +.Fn setclassenvironment +failed because it were unable to allocate memory for the environment. +.El .Sh SEE ALSO .Xr setgid 2 , .Xr setlogin 2 , diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c index 8e6506c1a7..4c7604ad12 100644 --- a/lib/libutil/login_class.c +++ b/lib/libutil/login_class.c @@ -22,7 +22,7 @@ * High-level routines relating to use of the user capabilities database * * $FreeBSD: src/lib/libutil/login_class.c,v 1.14.2.3 2002/08/06 07:07:52 ache Exp $ - * $DragonFly: src/lib/libutil/login_class.c,v 1.4 2005/03/04 04:31:11 cpressey Exp $ + * $DragonFly: src/lib/libutil/login_class.c,v 1.5 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -192,7 +192,7 @@ substvar(char * var, const struct passwd * pwd, int hlen, int pch, int nlen) } -void +int setclassenvironment(login_cap_t *lc, const struct passwd * pwd, int paths) { struct login_vars *vars = paths ? pathvars : envars; @@ -210,10 +210,17 @@ setclassenvironment(login_cap_t *lc, const struct passwd * pwd, int paths) char * np = substvar(var, pwd, hlen, pch, nlen); if (np != NULL) { - setenv(vars->var, np, vars->overwrite); + if (setenv(vars->var, np, vars->overwrite) == -1) { + syslog(LOG_ERR, "setclassenvironment: %m"); + free(np); + return -1; + } free(np); } else if (vars->def != NULL) { - setenv(vars->var, vars->def, 0); + if (setenv(vars->var, vars->def, 0) == -1) { + syslog(LOG_ERR, "setclassenvironment: %m"); + return -1; + } } ++vars; } @@ -234,7 +241,10 @@ setclassenvironment(login_cap_t *lc, const struct passwd * pwd, int paths) *p++ = '\0'; if ((np = substvar(p, pwd, hlen, pch, nlen)) != NULL) { - setenv(*set_env, np, 1); + if (setenv(*set_env, np, 1) == -1) { + free(np); + return -1; + } free(np); } } @@ -242,6 +252,7 @@ setclassenvironment(login_cap_t *lc, const struct passwd * pwd, int paths) } } } + return 0; } @@ -280,8 +291,9 @@ setclasscontext(const char *classname, unsigned int flags) static mode_t setlogincontext(login_cap_t *lc, const struct passwd *pwd, - mode_t mymask, unsigned long flags) + mode_t mymask, unsigned long flags, int *errcode) { + *errcode = 0; if (lc) { /* Set resources */ if (flags & LOGIN_SETRESOURCES) @@ -290,11 +302,15 @@ setlogincontext(login_cap_t *lc, const struct passwd *pwd, if (flags & LOGIN_SETUMASK) mymask = (mode_t)login_getcapnum(lc, "umask", mymask, mymask); /* Set paths */ - if (flags & LOGIN_SETPATH) - setclassenvironment(lc, pwd, 1); + if (flags & LOGIN_SETPATH) { + if (setclassenvironment(lc, pwd, 1) == -1) + *errcode = -1; + } /* Set environment */ - if (flags & LOGIN_SETENV) - setclassenvironment(lc, pwd, 0); + if (flags & LOGIN_SETENV) { + if (setclassenvironment(lc, pwd, 0) == -1) + *errcode = -1; + } } return mymask; } @@ -324,6 +340,7 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in #ifndef __NETBSD_SYSCALLS struct rtprio rtp; #endif + int errcode; if (lc == NULL) { if (pwd != NULL && (lc = login_getpwclass(pwd)) != NULL) @@ -389,7 +406,11 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in } mymask = (flags & LOGIN_SETUMASK) ? umask(LOGIN_DEFUMASK) : 0; - mymask = setlogincontext(lc, pwd, mymask, flags); + mymask = setlogincontext(lc, pwd, mymask, flags, &errcode); + if (errcode == -1) { + login_close(llc); + return -1; + } login_close(llc); /* This needs to be done after anything that needs root privs */ @@ -402,7 +423,11 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in * Now, we repeat some of the above for the user's private entries */ if ((lc = login_getuserclass(pwd)) != NULL) { - mymask = setlogincontext(lc, pwd, mymask, flags); + mymask = setlogincontext(lc, pwd, mymask, flags, &errcode); + if (errcode == -1) { + login_close(lc); + return -1; + } login_close(lc); } diff --git a/libexec/ftpd/popen.c b/libexec/ftpd/popen.c index b20d566fc3..548ed626ea 100644 --- a/libexec/ftpd/popen.c +++ b/libexec/ftpd/popen.c @@ -35,7 +35,7 @@ * * @(#)popen.c 8.3 (Berkeley) 4/6/94 * $FreeBSD: src/libexec/ftpd/popen.c,v 1.18.2.3 2001/08/09 00:53:18 mikeh Exp $ - * $DragonFly: src/libexec/ftpd/popen.c,v 1.2 2003/06/17 04:27:07 dillon Exp $ + * $DragonFly: src/libexec/ftpd/popen.c,v 1.3 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -146,7 +146,8 @@ ftpd_popen(program, type) closelog(); /* Trigger to sense new /etc/localtime after chroot */ if (getenv("TZ") == NULL) { - setenv("TZ", "", 0); + if (setenv("TZ", "", 0) == -1) + syslog(LOG_ERR, "setenv: cannot set TZ: %m"); tzset(); unsetenv("TZ"); tzset(); diff --git a/libexec/telnetd/state.c b/libexec/telnetd/state.c index 13f1eba453..576eb12dcb 100644 --- a/libexec/telnetd/state.c +++ b/libexec/telnetd/state.c @@ -32,7 +32,7 @@ * * @(#)state.c 8.5 (Berkeley) 5/30/95 * $FreeBSD: src/libexec/telnetd/state.c,v 1.9.2.4 2002/04/13 11:07:12 markm Exp $ - * $DragonFly: src/libexec/telnetd/state.c,v 1.2 2003/06/17 04:27:08 dillon Exp $ + * $DragonFly: src/libexec/telnetd/state.c,v 1.3 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -1162,7 +1162,8 @@ suboption(void) return; settimer(xdisplocsubopt); subpointer[SB_LEN()] = '\0'; - (void)setenv("DISPLAY", (char *)subpointer, 1); + if (setenv("DISPLAY", (char *)subpointer, 1) == -1) + syslog(LOG_ERR, "setenv: cannot set DISPLAY=%s: %m", (char *)subpointer); break; } /* end of case TELOPT_XDISPLOC */ @@ -1327,8 +1328,10 @@ suboption(void) case NEW_ENV_VAR: case ENV_USERVAR: *cp = '\0'; - if (valp) - (void)setenv(varp, valp, 1); + if (valp) { + if (setenv(varp, valp, 1) == -1) + syslog(LOG_ERR, "setenv: cannot set %s=%s: %m", varp, valp); + } else unsetenv(varp); cp = varp = (char *)subpointer; @@ -1346,8 +1349,10 @@ suboption(void) } } *cp = '\0'; - if (valp) - (void)setenv(varp, valp, 1); + if (valp) { + if (setenv(varp, valp, 1) == -1) + syslog(LOG_ERR, "setenv: cannot set %s=%s: %m", varp, valp); + } else unsetenv(varp); break; diff --git a/libexec/telnetd/sys_term.c b/libexec/telnetd/sys_term.c index 2eff0429c8..98b17fa9ef 100644 --- a/libexec/telnetd/sys_term.c +++ b/libexec/telnetd/sys_term.c @@ -32,7 +32,7 @@ * * @(#)sys_term.c 8.4+1 (Berkeley) 5/30/95 * $FreeBSD: src/libexec/telnetd/sys_term.c,v 1.24.2.8 2002/06/17 02:48:06 jmallett Exp $ - * $DragonFly: src/libexec/telnetd/sys_term.c,v 1.2 2003/06/17 04:27:08 dillon Exp $ + * $DragonFly: src/libexec/telnetd/sys_term.c,v 1.3 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -1026,11 +1026,15 @@ start_login(char *host undef1, int autologin undef1, char *name undef1) * "real" or "kludge" if we are operating in either * real or kludge linemode. */ - if (lmodetype == REAL_LINEMODE) - setenv("LINEMODE", "real", 1); + if (lmodetype == REAL_LINEMODE) { + if (setenv("LINEMODE", "real", 1) == -1) + syslog(LOG_ERR, "setenv: cannot set LINEMODE=real: %m"); + } # ifdef KLUDGELINEMODE - else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK) - setenv("LINEMODE", "kludge", 1); + else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK) { + if (setenv("LINEMODE", "kludge", 1) == -1) + syslog(LOG_ERR, "setenv: cannot set LINEMODE=kludge: %m"); + } # endif #endif #ifdef BFTPDAEMON diff --git a/libexec/telnetd/telnetd.c b/libexec/telnetd/telnetd.c index f5a15a1e6e..744a0ba0a7 100644 --- a/libexec/telnetd/telnetd.c +++ b/libexec/telnetd/telnetd.c @@ -32,7 +32,7 @@ * * @(#)telnetd.c 8.4 (Berkeley) 5/30/95 * $FreeBSD: src/libexec/telnetd/telnetd.c,v 1.22.2.8 2002/04/13 11:07:12 markm Exp $ - * $DragonFly: src/libexec/telnetd/telnetd.c,v 1.2 2003/06/17 04:27:08 dillon Exp $ + * $DragonFly: src/libexec/telnetd/telnetd.c,v 1.3 2006/01/12 13:43:10 corecode Exp $ */ #include "telnetd.h" @@ -590,7 +590,8 @@ doit(struct sockaddr *who) */ *user_name = 0; level = getterminaltype(user_name); - setenv("TERM", terminaltype ? terminaltype : "network", 1); + if (setenv("TERM", terminaltype ? terminaltype : "network", 1) == -1) + syslog(LOG_ERR, "setenv: cannot set TERM=%s: %m", terminaltype ? terminaltype : "network"); telnet(net, pty, remote_hostname); /* begin server process */ diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c index 0175272537..7150e25888 100644 --- a/usr.bin/du/du.c +++ b/usr.bin/du/du.c @@ -36,7 +36,7 @@ * @(#) Copyright (c) 1989, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)du.c 8.5 (Berkeley) 5/4/95 * $FreeBSD: src/usr.bin/du/du.c,v 1.17.2.4 2002/12/12 16:29:39 trhodes Exp $ - * $DragonFly: src/usr.bin/du/du.c,v 1.8 2005/09/01 22:19:26 liamfoy Exp $ + * $DragonFly: src/usr.bin/du/du.c,v 1.9 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -155,13 +155,15 @@ main(int argc, char **argv) cflag = 1; break; case 'h': - putenv("BLOCKSIZE=512"); + if (putenv("BLOCKSIZE=512") == -1) + warn("putenv: cannot set BLOCKSIZE=512"); hflag = 1; valp = vals_base2; break; case 'k': hflag = 0; - putenv("BLOCKSIZE=1024"); + if (putenv("BLOCKSIZE=1024") == -1) + warn("putenv: cannot set BLOCKSIZE=1024"); break; case 'r': /* Compatibility. */ break; diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c index ebefd7b2a8..468649bd50 100644 --- a/usr.bin/env/env.c +++ b/usr.bin/env/env.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1988, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)env.c 8.3 (Berkeley) 4/2/94 * $FreeBSD: src/usr.bin/env/env.c,v 1.5.2.3 2002/06/26 08:23:36 tjr Exp $ - * $DragonFly: src/usr.bin/env/env.c,v 1.4 2004/12/08 20:17:12 liamfoy Exp $ + * $DragonFly: src/usr.bin/env/env.c,v 1.5 2006/01/12 13:43:10 corecode Exp $ */ #include @@ -66,7 +66,7 @@ main(int argc, char **argv) } for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) { if (setenv(*argv, ++p, 1) == -1) - err(1, "%s", *argv); + err(1, "setenv: cannot set %s=%s", *argv, p); } if (*argv) { diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index 60e1599109..3093624288 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/usr.bin/fetch/fetch.c,v 1.10.2.21 2003/06/06 06:48:42 des Exp $ - * $DragonFly: src/usr.bin/fetch/fetch.c,v 1.5 2005/01/04 23:08:13 dillon Exp $ + * $DragonFly: src/usr.bin/fetch/fetch.c,v 1.6 2006/01/12 13:43:11 corecode Exp $ */ #include @@ -905,8 +905,10 @@ main(int argc, char *argv[]) /* authentication */ if (v_tty) fetchAuthMethod = query_auth; - if (N_filename != NULL) - setenv("NETRC", N_filename, 1); + if (N_filename != NULL) { + if (setenv("NETRC", N_filename, 1) == -1) + err("setenv: cannot set NETRC=%s", N_filename); + } while (argc) { if ((p = strrchr(*argv, '/')) == NULL) diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c index 1bd1af9705..a701d5bca4 100644 --- a/usr.bin/ldd/ldd.c +++ b/usr.bin/ldd/ldd.c @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/usr.bin/ldd/ldd.c,v 1.18.2.7 2002/02/27 18:35:53 sobomax Exp $ - * $DragonFly: src/usr.bin/ldd/ldd.c,v 1.5 2005/07/24 15:04:56 joerg Exp $ + * $DragonFly: src/usr.bin/ldd/ldd.c,v 1.6 2006/01/12 13:43:11 corecode Exp $ */ #include @@ -98,11 +98,16 @@ main(int argc, char **argv) #endif /* ld.so magic */ - setenv("LD_TRACE_LOADED_OBJECTS", "1", 1); - if (fmt1) - setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1); - if (fmt2) - setenv("LD_TRACE_LOADED_OBJECTS_FMT2", fmt2, 1); + if (setenv("LD_TRACE_LOADED_OBJECTS", "1", 1) == -1) + err(1, "setenv: cannot set LD_TRACE_LOADED_OBJECTS=1"); + if (fmt1) { + if (setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1) == -1) + err(1, "setenv: cannot set LD_TRACE_LOADED_OBJECTS_FMT1=%s", fmt1); + } + if (fmt2) { + if (setenv("LD_TRACE_LOADED_OBJECTS_FMT2", fmt2, 1) == -1) + err(1, "setenv: cannot set LD_TRACE_LOADED_OBJECTS_FMT2=%s", fmt2); + } rval = 0; for ( ; argc > 0; argc--, argv++) { @@ -180,7 +185,8 @@ main(int argc, char **argv) continue; } - setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1); + if (setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1) == -1) + err(1, "setenv: cannot set LD_TRACE_LOADED_OBJECTS_PROGNAME=%s", *argv); if (fmt1 == NULL && fmt2 == NULL) /* Default formats */ printf("%s:\n", *argv); diff --git a/usr.bin/limits/limits.c b/usr.bin/limits/limits.c index bbcae0e06a..6a4081a2c1 100644 --- a/usr.bin/limits/limits.c +++ b/usr.bin/limits/limits.c @@ -21,7 +21,7 @@ * Display/change(+runprogram)/eval resource limits. * * $FreeBSD: src/usr.bin/limits/limits.c,v 1.7.2.3 2003/05/22 09:26:57 sheldonh Exp $ - * $DragonFly: src/usr.bin/limits/limits.c,v 1.4 2005/01/12 01:20:26 cpressey Exp $ + * $DragonFly: src/usr.bin/limits/limits.c,v 1.5 2006/01/12 13:43:11 corecode Exp $ */ #include @@ -433,8 +433,10 @@ main(int argc, char *argv[]) login_close(lc); /* set leading environment variables, like eval(1) */ - while (*argv && (p = strchr(*argv, '='))) - (void)setenv(*argv++, ++p, 1); + while (*argv && (p = strchr(*argv, '='))) { + if (setenv(*argv++, ++p, 1) == -1) + err(1, "setenv: cannot set %s=%s", *argv, p); + } /* Set limits */ for (rcswhich = 0; rcswhich < RLIM_NLIMITS; rcswhich++) { diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c index 035335a3aa..a21f883535 100644 --- a/usr.bin/login/login.c +++ b/usr.bin/login/login.c @@ -32,7 +32,7 @@ * * @(#)login.c 8.4 (Berkeley) 4/2/94 * $FreeBSD: src/usr.bin/login/login.c,v 1.51.2.15 2003/04/29 14:10:41 des Exp $ - * $DragonFly: src/usr.bin/login/login.c,v 1.5 2005/07/13 12:34:22 joerg Exp $ + * $DragonFly: src/usr.bin/login/login.c,v 1.6 2006/01/12 13:43:11 corecode Exp $ */ #if 0 @@ -656,16 +656,24 @@ main(int argc, char **argv) exit(1); } - (void)setenv("SHELL", pwd->pw_shell, 1); - (void)setenv("HOME", pwd->pw_dir, 1); - if (term != NULL && *term != '\0') - (void)setenv("TERM", term, 1); /* Preset overrides */ + if (setenv("SHELL", pwd->pw_shell, 1) == -1) + err(1, "setenv: cannot set SHELL=%s", pwd->pw_shell); + if (setenv("HOME", pwd->pw_dir, 1) == -1) + err(1, "setenv: cannot set HOME=%s", pwd->pw_dir); + if (term != NULL && *term != '\0') { + if (setenv("TERM", term, 1) == -1) /* Preset overrides */ + err(1, "setenv: cannot set TERM=%s", term); + } else { - (void)setenv("TERM", stypeof(tty), 0); /* Fallback doesn't */ + if (setenv("TERM", stypeof(tty), 0) == -1) /* Fallback doesn't */ + err(1, "setenv: cannot set TERM=%s", stypeof(tty)); } - (void)setenv("LOGNAME", username, 1); - (void)setenv("USER", username, 1); - (void)setenv("PATH", rootlogin ? _PATH_STDPATH : _PATH_DEFPATH, 0); + if (setenv("LOGNAME", username, 1) == -1) + err(1, "setenv: cannot set LOGNAME=%s", username); + if (setenv("USER", username, 1) == -1) + err(1, "setenv: cannot set USER=%s", username); + if (setenv("PATH", rootlogin ? _PATH_STDPATH : _PATH_DEFPATH, 0) == -1) + err(1, "setenv: cannot set PATH=%s", rootlogin ? _PATH_STDPATH : _PATH_DEFPATH); if (!quietlog) { char *cw; @@ -857,8 +865,10 @@ export_pam_environment(void) char **pp; for (pp = environ_pam; *pp != NULL; pp++) { - if (ok_to_export(*pp)) - (void) putenv(*pp); + if (ok_to_export(*pp)) { + if (putenv(*pp) == -1) + err(1, "putenv: cannot set %s", *pp); + } free(*pp); } return PAM_SUCCESS; diff --git a/usr.bin/objformat/objformat.c b/usr.bin/objformat/objformat.c index 019150dda8..6c615c25aa 100644 --- a/usr.bin/objformat/objformat.c +++ b/usr.bin/objformat/objformat.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/usr.bin/objformat/objformat.c,v 1.6 1998/10/24 02:01:30 jdp Exp $ - * $DragonFly: src/usr.bin/objformat/objformat.c,v 1.18 2005/12/21 16:48:06 joerg Exp $ + * $DragonFly: src/usr.bin/objformat/objformat.c,v 1.19 2006/01/12 13:43:11 corecode Exp $ */ #include @@ -170,7 +170,8 @@ main(int argc, char **argv) path = strdup(objformat_path); - setenv("OBJFORMAT", objformat, 1); + if (setenv("OBJFORMAT", objformat, 1) == -1) + err(1, "setenv: cannot set OBJFORMAT=%s", objformat); /* * objformat_path could be sequence of colon-separated paths. diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c index b438585aca..900f8933da 100644 --- a/usr.bin/su/su.c +++ b/usr.bin/su/su.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1988, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)su.c 8.3 (Berkeley) 4/2/94 * $FreeBSD: src/usr.bin/su/su.c,v 1.34.2.4 2002/06/16 21:04:15 nectar Exp $ - * $DragonFly: src/usr.bin/su/su.c,v 1.8 2005/03/14 11:55:33 joerg Exp $ + * $DragonFly: src/usr.bin/su/su.c,v 1.9 2006/01/12 13:43:11 corecode Exp $ */ #include @@ -396,21 +396,30 @@ main(int argc, char **argv) /* set the su'd user's environment & umask */ setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETPATH|LOGIN_SETUMASK|LOGIN_SETENV); #else - setenv("PATH", _PATH_DEFPATH, 1); + if (setenv("PATH", _PATH_DEFPATH, 1) == -1) + err(1, "setenv: cannot set PATH=%s", _PATH_DEFPATH); #endif - if (p) - setenv("TERM", p, 1); + if (p) { + if (setenv("TERM", p, 1) == -1) + err(1, "setenv: cannot set TERM=%s", p); + } #ifdef KERBEROS5 - if (ccname) - setenv("KRB5CCNAME", ccname, 1); + if (ccname) { + if (setenv("KRB5CCNAME", ccname, 1) == -1) + err(1, "setenv: cannot set KRB5CCNAME=%s", ccname); + } #endif if (chdir(pwd->pw_dir) < 0) errx(1, "no directory"); } - if (asthem || pwd->pw_uid) - setenv("USER", pwd->pw_name, 1); - setenv("HOME", pwd->pw_dir, 1); - setenv("SHELL", shell, 1); + if (asthem || pwd->pw_uid) { + if (setenv("USER", pwd->pw_name, 1) == -1) + err(1, "setenv: cannot set USER=%s", pwd->pw_name); + } + if (setenv("HOME", pwd->pw_dir, 1) == -1) + err(1, "setenv: cannot set HOME=%s", pwd->pw_dir); + if (setenv("SHELL", shell, 1) == -1) + err(1, "setenv: cannot set SHELL=%s", shell); } if (iscsh == YES) { if (fastlogin) diff --git a/usr.bin/tabs/tabs.c b/usr.bin/tabs/tabs.c index 7b0039cfa2..457b8fdd3c 100644 --- a/usr.bin/tabs/tabs.c +++ b/usr.bin/tabs/tabs.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/usr.bin/tabs/tabs.c,v 1.3 2002/06/08 11:33:22 tjr Exp $ - * $DragonFly: src/usr.bin/tabs/tabs.c,v 1.1 2004/06/19 22:03:08 hmp Exp $ + * $DragonFly: src/usr.bin/tabs/tabs.c,v 1.2 2006/01/12 13:43:11 corecode Exp $ */ /* @@ -108,12 +108,15 @@ main(int argc __unused, char *argv[]) errx(1, "%s: invalid increment", arg + 1); } else if (arg[1] == 'T') { /* -Ttype or -T type */ - if (arg[2] != '\0') - setenv("TERM", arg + 2, 1); + if (arg[2] != '\0') { + if (setenv("TERM", arg + 2, 1) == -1) + err(1, "setenv: cannot set TERM=%s", arg + 2); + } else { if ((arg = *++argv) == NULL) usage(); - setenv("TERM", arg, 1); + if (setenv("TERM", arg, 1) == -1) + err(1, "setenv: cannot set TERM=%s", arg); } } else if (arg[1] == '-') { arg = *++argv; diff --git a/usr.bin/whereis/whereis.c b/usr.bin/whereis/whereis.c index e91c4f1a3d..d808541784 100644 --- a/usr.bin/whereis/whereis.c +++ b/usr.bin/whereis/whereis.c @@ -22,7 +22,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * $FreeBSD: src/usr.bin/whereis/whereis.c,v 1.12 2002/08/22 01:50:51 johan Exp $ - * $DragonFly: src/usr.bin/whereis/whereis.c,v 1.3 2005/08/31 16:45:51 liamfoy Exp $ + * $DragonFly: src/usr.bin/whereis/whereis.c,v 1.4 2006/01/12 13:43:11 corecode Exp $ */ /* @@ -383,7 +383,8 @@ main(int argc, char **argv) errx(EX_DATAERR, "no directories to search"); if (opt_m) { - setenv("MANPATH", colonify(mandirs), 1); + if (setenv("MANPATH", colonify(mandirs), 1) == -1) + err(1, "setenv: cannot set MANPATH=%s", colonify(mandirs)); if ((i = regcomp(&re, MANWHEREISMATCH, REG_EXTENDED)) != 0) { regerror(i, &re, buf, BUFSIZ - 1); errx(EX_UNAVAILABLE, "regcomp(%s) failed: %s", diff --git a/usr.bin/window/wwenviron.c b/usr.bin/window/wwenviron.c index ca0c284c8a..0a234a05ce 100644 --- a/usr.bin/window/wwenviron.c +++ b/usr.bin/window/wwenviron.c @@ -35,7 +35,7 @@ * * @(#)wwenviron.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/window/wwenviron.c,v 1.2.6.1 2001/05/17 09:45:01 obrien Exp $ - * $DragonFly: src/usr.bin/window/wwenviron.c,v 1.2 2003/06/17 04:29:34 dillon Exp $ + * $DragonFly: src/usr.bin/window/wwenviron.c,v 1.3 2006/01/12 13:43:11 corecode Exp $ */ #include "ww.h" @@ -92,9 +92,11 @@ register struct ww *wp; */ (void) sprintf(buf, "%sco#%d:li#%d:%s", WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr, wwwintermcap); - (void) setenv("TERMCAP", buf, 1); + if (setenv("TERMCAP", buf, 1) == -1) + err(1, "setenv: cannot set TERMCAP=%s", buf); (void) sprintf(buf, "%d", wp->ww_id + 1); - (void) setenv("WINDOW_ID", buf, 1); + if (setenv("WINDOW_ID", buf, 1) == -1) + err(1, "setenv: cannot set WINDOW_ID=%s", buf); return 0; bad: wwerrno = WWE_SYS; diff --git a/usr.bin/window/wwinit.c b/usr.bin/window/wwinit.c index 8ac03e443a..c490a8bec2 100644 --- a/usr.bin/window/wwinit.c +++ b/usr.bin/window/wwinit.c @@ -35,7 +35,7 @@ * * @(#)wwinit.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/window/wwinit.c,v 1.11.2.1 2001/05/17 09:45:01 obrien Exp $ - * $DragonFly: src/usr.bin/window/wwinit.c,v 1.2 2003/06/17 04:29:34 dillon Exp $ + * $DragonFly: src/usr.bin/window/wwinit.c,v 1.3 2006/01/12 13:43:11 corecode Exp $ */ #include "ww.h" @@ -303,7 +303,8 @@ wwinit() * since tt_init() has already made its own copy of it and * wwterm now points to the copy. */ - (void) setenv("TERM", WWT_TERM, 1); + if (setenv("TERM", WWT_TERM, 1) == -1) + err(1, "setenv: cannot set TERM=%s", WWT_TERM); #ifdef TERMINFO if (wwterminfoinit() < 0) goto bad; diff --git a/usr.bin/window/wwterminfo.c b/usr.bin/window/wwterminfo.c index 4085897a2d..48520b59cb 100644 --- a/usr.bin/window/wwterminfo.c +++ b/usr.bin/window/wwterminfo.c @@ -35,7 +35,7 @@ * * @(#)wwterminfo.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/window/wwterminfo.c,v 1.3.6.2 2001/05/17 19:40:13 eric Exp $ - * $DragonFly: src/usr.bin/window/wwterminfo.c,v 1.2 2003/06/17 04:29:34 dillon Exp $ + * $DragonFly: src/usr.bin/window/wwterminfo.c,v 1.3 2006/01/12 13:43:11 corecode Exp $ */ #ifdef TERMINFO @@ -68,7 +68,8 @@ wwterminfoinit() wwerrno = WWE_SYS; return -1; } - (void) setenv("TERMINFO", wwterminfopath, 1); + if (setenv("TERMINFO", wwterminfopath, 1) == -1) + err(1, "setenv: cannot set TERMINFO=%s", wwterminfopath); /* make a termcap entry and turn it into terminfo */ (void) sprintf(buf, "%s/cap", wwterminfopath); if ((fp = fopen(buf, "w")) == NULL) { diff --git a/usr.sbin/cron/cron/cron.c b/usr.sbin/cron/cron/cron.c index 0d2c36ed01..f1c856b0cf 100644 --- a/usr.sbin/cron/cron/cron.c +++ b/usr.sbin/cron/cron/cron.c @@ -15,7 +15,7 @@ * Paul Vixie uunet!decwrl!vixie!paul * * $FreeBSD: src/usr.sbin/cron/cron/cron.c,v 1.9.2.2 2001/05/28 23:37:26 babkin Exp $ - * $DragonFly: src/usr.sbin/cron/cron/cron.c,v 1.6 2004/12/18 22:48:03 swildner Exp $ + * $DragonFly: src/usr.sbin/cron/cron/cron.c,v 1.7 2006/01/12 13:43:11 corecode Exp $ */ #define MAIN_PROGRAM @@ -88,7 +88,11 @@ main(int argc, char **argv) set_cron_cwd(); #if defined(POSIX) - setenv("PATH", _PATH_DEFPATH, 1); + if (setenv("PATH", _PATH_DEFPATH, 1) == -1) { + log_it("CRON", getpid(), "DEATH", + "setenv: cannot set PATH"); + exit(0); + } #endif /* if there are no debug flags turned on, fork as a daemon should. diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c index 450839b921..f7dedb26ec 100644 --- a/usr.sbin/inetd/inetd.c +++ b/usr.sbin/inetd/inetd.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1983, 1991, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)from: inetd.c 8.4 (Berkeley) 4/13/94 * $FreeBSD: src/usr.sbin/inetd/inetd.c,v 1.80.2.11 2003/04/05 13:39:18 dwmalone Exp $ - * $DragonFly: src/usr.sbin/inetd/inetd.c,v 1.8 2005/03/21 19:26:14 liamfoy Exp $ + * $DragonFly: src/usr.sbin/inetd/inetd.c,v 1.9 2006/01/12 13:43:11 corecode Exp $ */ /* @@ -504,7 +504,9 @@ main(int argc, char **argv) memset(dummy, 'x', DUMMYSIZE - 1); dummy[DUMMYSIZE - 1] = '\0'; - setenv("inetd_dummy", dummy, 1); + if (setenv("inetd_dummy", dummy, 1) == -1) + syslog(LOG_WARN, "setenv: cannot set inetd_dummy=%s: %m", dummy); + } if (pipe(signalpipe) != 0) { diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c index 884152eefc..cc60bd6e38 100644 --- a/usr.sbin/pstat/pstat.c +++ b/usr.sbin/pstat/pstat.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1980, 1991, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)pstat.c 8.16 (Berkeley) 5/9/95 * $FreeBSD: src/usr.sbin/pstat/pstat.c,v 1.49.2.5 2002/07/12 09:12:49 des Exp $ - * $DragonFly: src/usr.sbin/pstat/pstat.c,v 1.15 2005/03/17 17:28:44 dillon Exp $ + * $DragonFly: src/usr.sbin/pstat/pstat.c,v 1.16 2006/01/12 13:43:11 corecode Exp $ */ #define _KERNEL_STRUCTURES @@ -226,7 +226,8 @@ main(int argc, char **argv) fileflag = 1; break; case 'k': - putenv("BLOCKSIZE=1K"); + if (putenv("BLOCKSIZE=1K") == -1) + warn("putenv: cannot set BLOCKSIZE=1K"); break; case 'M': memf = optarg; diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c index 1ddd2a2d03..da768b6482 100644 --- a/usr.sbin/tzsetup/tzsetup.c +++ b/usr.sbin/tzsetup/tzsetup.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/usr.sbin/tzsetup/tzsetup.c,v 1.16.2.2 2002/03/06 06:17:41 obrien Exp $ - * $DragonFly: src/usr.sbin/tzsetup/tzsetup.c,v 1.5 2005/12/05 02:40:28 swildner Exp $ + * $DragonFly: src/usr.sbin/tzsetup/tzsetup.c,v 1.6 2006/01/12 13:43:11 corecode Exp $ */ /* @@ -586,7 +586,8 @@ confirm_zone(const char *filename) time_t t = time(0); int rv; - setenv("TZ", filename, 1); + if (setenv("TZ", filename, 1) == -1) + err(1, "setenv: cannot set TZ=%s", filename); tzset(); tm = localtime(&t); -- 2.41.0