diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2000-09-15 07:13:52 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2000-09-15 07:13:52 +0000 |
commit | 42a3e69c05af72afbc1d37574fba7729b828289b (patch) | |
tree | becf08be7a11e201542de4de93b8cd0f8650f9e1 | |
parent | b74ef7bac5077f29fc1c12e8b5ccaf0e2f1f8fdc (diff) |
check return value for setenv(3) for failure, and deal appropriately
-rw-r--r-- | bin/date/date.c | 7 | ||||
-rw-r--r-- | gnu/libexec/ld.so/ldd/ldd.c | 9 | ||||
-rw-r--r-- | gnu/usr.bin/ld/ldd/ldd.c | 14 | ||||
-rw-r--r-- | lib/libtelnet/kerberos.c | 11 | ||||
-rw-r--r-- | libexec/ftpd/ftpd.c | 20 | ||||
-rw-r--r-- | libexec/rexecd/rexecd.c | 11 | ||||
-rw-r--r-- | libexec/rshd/rshd.c | 12 | ||||
-rw-r--r-- | libexec/telnetd/state.c | 7 | ||||
-rw-r--r-- | libexec/telnetd/sys_term.c | 8 | ||||
-rw-r--r-- | libexec/telnetd/telnetd.c | 6 | ||||
-rw-r--r-- | usr.bin/env/env.1 | 7 | ||||
-rw-r--r-- | usr.bin/env/env.c | 25 | ||||
-rw-r--r-- | usr.bin/login/login.c | 52 | ||||
-rw-r--r-- | usr.bin/ssh/ssh-agent.c | 11 | ||||
-rw-r--r-- | usr.bin/su/su.c | 26 | ||||
-rw-r--r-- | usr.bin/vi/ex/ex_script.c | 7 | ||||
-rw-r--r-- | usr.sbin/cron/cron.c | 7 | ||||
-rw-r--r-- | usr.sbin/pppd/main.c | 10 |
18 files changed, 157 insertions, 93 deletions
diff --git a/bin/date/date.c b/bin/date/date.c index 0f46a9f678e..29bbccd08ac 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -1,4 +1,4 @@ -/* $OpenBSD: date.c,v 1.14 2000/01/22 20:24:48 deraadt Exp $ */ +/* $OpenBSD: date.c,v 1.15 2000/09/15 07:13:43 deraadt Exp $ */ /* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: date.c,v 1.14 2000/01/22 20:24:48 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: date.c,v 1.15 2000/09/15 07:13:43 deraadt Exp $"; #endif #endif /* not lint */ @@ -99,7 +99,8 @@ main(argc, argv) tval = atol(optarg); break; case 'u': /* do everything in UTC */ - (void)setenv("TZ", "GMT0", 1); + if (setenv("TZ", "GMT0", 1) == -1) + err(1, "cannot unsetenv TZ"); break; case 't': /* minutes west of GMT */ /* error check; don't allow "PST" */ diff --git a/gnu/libexec/ld.so/ldd/ldd.c b/gnu/libexec/ld.so/ldd/ldd.c index 6cb11b2b6a3..78a37bc75c1 100644 --- a/gnu/libexec/ld.so/ldd/ldd.c +++ b/gnu/libexec/ld.so/ldd/ldd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldd.c,v 1.2 1998/01/28 10:52:45 pefo Exp $ */ +/* $OpenBSD: ldd.c,v 1.3 2000/09/15 07:13:44 deraadt Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom @@ -77,7 +77,12 @@ main(argc, argv) else if(lflag && readsoneeded(f, 1)) { fclose(f); - setenv("LD_TRACE_LOADED_OBJECTS", "1", 1); + if (setenv("LD_TRACE_LOADED_OBJECTS", "1", 1) == -1) { + fprintf(stderr, + "%s: can't setenv LD_TRACE_LOADED_OBJECTS\n", + argv[0]); + exit(2); + } execl(argv[i], NULL); } exit(0); diff --git a/gnu/usr.bin/ld/ldd/ldd.c b/gnu/usr.bin/ld/ldd/ldd.c index c61de2a388f..cbac7194497 100644 --- a/gnu/usr.bin/ld/ldd/ldd.c +++ b/gnu/usr.bin/ld/ldd/ldd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldd.c,v 1.5 1999/05/21 01:20:45 espie Exp $ */ +/* $OpenBSD: ldd.c,v 1.6 2000/09/15 07:13:44 deraadt Exp $ */ /* $NetBSD: ldd.c,v 1.12 1995/10/09 00:14:41 pk Exp $ */ /* * Copyright (c) 1993 Paul Kranenburg @@ -87,11 +87,14 @@ char *argv[]; } /* ld.so magic */ - setenv("LD_TRACE_LOADED_OBJECTS", "", 1); + if (setenv("LD_TRACE_LOADED_OBJECTS", "", 1) == -1) + err(1, "cannot setenv LD_TRACE_LOADED_OBJECTS"); if (fmt1) - setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1); + if (setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1) == -1) + err(1, "cannot setenv LD_TRACE_LOADED_OBJECTS_FMT1"); if (fmt2) - setenv("LD_TRACE_LOADED_OBJECTS_FMT2", fmt2, 1); + if (setenv("LD_TRACE_LOADED_OBJECTS_FMT2", fmt2, 1) == -1) + err(1, "cannot setenv LD_TRACE_LOADED_OBJECTS_FMT2"); rval = 0; while (argc--) { @@ -132,7 +135,8 @@ char *argv[]; } (void)close(fd); - setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1); + if (setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1) == -1) + err(1, "cannot setenv LD_TRACE_LOADED_OBJECTS_PROGNAME"); if (fmt1 == NULL && fmt2 == NULL) /* Default formats */ printf("%s:\n", *argv); diff --git a/lib/libtelnet/kerberos.c b/lib/libtelnet/kerberos.c index 0f1c73ab857..b08e1bbbfcc 100644 --- a/lib/libtelnet/kerberos.c +++ b/lib/libtelnet/kerberos.c @@ -1,5 +1,5 @@ -/* $OpenBSD: kerberos.c,v 1.4 2000/07/11 15:52:13 deraadt Exp $ */ -/* $Id: kerberos.c,v 1.4 2000/07/11 15:52:13 deraadt Exp $ */ +/* $OpenBSD: kerberos.c,v 1.5 2000/09/15 07:13:44 deraadt Exp $ */ +/* $Id: kerberos.c,v 1.5 2000/09/15 07:13:44 deraadt Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -320,11 +320,10 @@ kerberos4_is(Authenticator *ap, unsigned char *data, int cnt) char ts[MAXPATHLEN]; struct passwd *pw = getpwnam(UserNameRequested); - if(pw){ + if (pw) { snprintf(ts, sizeof(ts), - "%s%u", - TKT_ROOT, - (unsigned)pw->pw_uid); + "%s%u", TKT_ROOT, (unsigned)pw->pw_uid); + /* XXX allocation failure? */ setenv("KRBTKFILE", ts, 1); } Data(ap, KRB_ACCEPT, NULL, 0); diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index 66b1acd75c0..0d1a817b7d0 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftpd.c,v 1.78 2000/08/20 18:42:37 millert Exp $ */ +/* $OpenBSD: ftpd.c,v 1.79 2000/09/15 07:13:45 deraadt Exp $ */ /* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */ /* @@ -977,14 +977,20 @@ skip: goto bad; } strcpy(pw->pw_dir, "/"); - setenv("HOME", "/", 1); + if (setenv("HOME", "/", 1) == -1) { + reply(550, "Can't setup environment."); + goto bad; + } } else if (dochroot) { if (chroot(rootdir) < 0 || chdir("/") < 0) { reply(550, "Can't change root."); goto bad; } strcpy(pw->pw_dir, "/"); - setenv("HOME", "/", 1); + if (setenv("HOME", "/", 1) == -1) { + reply(550, "Can't setup environment."); + goto bad; + } } else if (chdir(pw->pw_dir) < 0) { if (chdir("/") < 0) { reply(530, "User %s: can't change directory to %s.", @@ -1003,8 +1009,12 @@ skip: /* * Set home directory so that use of ~ (tilde) works correctly. */ - if (getcwd(homedir, MAXPATHLEN) != NULL) - setenv("HOME", homedir, 1); + if (getcwd(homedir, MAXPATHLEN) != NULL) { + if (setenv("HOME", homedir, 1) == -1) { + reply(550, "Can't setup environment."); + goto bad; + } + } /* * Display a login message, if it exists. diff --git a/libexec/rexecd/rexecd.c b/libexec/rexecd/rexecd.c index a22d773aecc..1cebbf62545 100644 --- a/libexec/rexecd/rexecd.c +++ b/libexec/rexecd/rexecd.c @@ -39,7 +39,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)rexecd.c 5.12 (Berkeley) 2/25/91";*/ -static char rcsid[] = "$Id: rexecd.c,v 1.13 2000/08/20 18:42:38 millert Exp $"; +static char rcsid[] = "$Id: rexecd.c,v 1.14 2000/09/15 07:13:46 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -260,10 +260,11 @@ doit(f, fromp) (void) close(f); environ = envinit; - setenv("HOME", pwd->pw_dir, 1); - setenv("SHELL", pwd->pw_shell, 1); - setenv("LOGNAME", pwd->pw_name, 1); - setenv("USER", pwd->pw_name, 1); + if (setenv("HOME", pwd->pw_dir, 1) == -1 || + setenv("SHELL", pwd->pw_shell, 1) == -1 || + setenv("LOGNAME", pwd->pw_name, 1) == -1 || + setenv("USER", pwd->pw_name, 1) == -1) + err(1, "unable to setup environment"); if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETALL)) err(1, "unable to set user context"); diff --git a/libexec/rshd/rshd.c b/libexec/rshd/rshd.c index 55aa2446fb0..1b3c8fb377d 100644 --- a/libexec/rshd/rshd.c +++ b/libexec/rshd/rshd.c @@ -39,7 +39,7 @@ static char copyright[] = #ifndef lint /* from: static char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94"; */ -static char *rcsid = "$Id: rshd.c,v 1.32 2000/08/20 18:42:38 millert Exp $"; +static char *rcsid = "$Id: rshd.c,v 1.33 2000/09/15 07:13:47 deraadt Exp $"; #endif /* not lint */ /* @@ -721,10 +721,12 @@ fail: pwd->pw_shell = _PATH_BSHELL; environ = envinit; - setenv("HOME", pwd->pw_dir, 1); - setenv("SHELL", pwd->pw_shell, 1); - setenv("USER", pwd->pw_name, 1); - setenv("LOGNAME", pwd->pw_name, 1); + if (setenv("HOME", pwd->pw_dir, 1) == -1 || + setenv("SHELL", pwd->pw_shell, 1) == -1 || + setenv("USER", pwd->pw_name, 1) == -1 || + setenv("LOGNAME", pwd->pw_name, 1) == -1) + errx(1, "cannot setup environment"); + if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETALL)) errx(1, "cannot set user context"); diff --git a/libexec/telnetd/state.c b/libexec/telnetd/state.c index 312152ad024..ac4e8d23a3c 100644 --- a/libexec/telnetd/state.c +++ b/libexec/telnetd/state.c @@ -1,4 +1,4 @@ -/* $OpenBSD: state.c,v 1.9 1998/08/21 17:12:22 art Exp $ */ +/* $OpenBSD: state.c,v 1.10 2000/09/15 07:13:47 deraadt Exp $ */ /* $NetBSD: state.c,v 1.9 1996/02/28 20:38:19 thorpej Exp $ */ /* @@ -39,7 +39,7 @@ static char sccsid[] = "@(#)state.c 8.5 (Berkeley) 5/30/95"; static char rcsid[] = "$NetBSD: state.c,v 1.9 1996/02/28 20:38:19 thorpej Exp $"; #else -static char rcsid[] = "$OpenBSD: state.c,v 1.9 1998/08/21 17:12:22 art Exp $"; +static char rcsid[] = "$OpenBSD: state.c,v 1.10 2000/09/15 07:13:47 deraadt Exp $"; #endif #endif /* not lint */ @@ -1287,6 +1287,7 @@ suboption() return; settimer(xdisplocsubopt); subpointer[SB_LEN()] = '\0'; + /* XXX allocation failure? */ (void)setenv("DISPLAY", (char *)subpointer, 1); break; } /* end of case TELOPT_XDISPLOC */ @@ -1455,6 +1456,7 @@ suboption() *cp = '\0'; if (envvarok(varp)) { if (valp) + /* XXX allocation failure? */ (void)setenv(varp, valp, 1); else unsetenv(varp); @@ -1476,6 +1478,7 @@ suboption() *cp = '\0'; if (envvarok(varp)) { if (valp) + /* XXX allocation failure? */ (void)setenv(varp, valp, 1); else unsetenv(varp); diff --git a/libexec/telnetd/sys_term.c b/libexec/telnetd/sys_term.c index 98985c2562a..3279213f2d9 100644 --- a/libexec/telnetd/sys_term.c +++ b/libexec/telnetd/sys_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_term.c,v 1.18 1999/08/17 09:13:13 millert Exp $ */ +/* $OpenBSD: sys_term.c,v 1.19 2000/09/15 07:13:47 deraadt Exp $ */ /* $NetBSD: sys_term.c,v 1.9 1996/03/20 04:25:53 tls Exp $ */ /* @@ -39,7 +39,7 @@ static char sccsid[] = "@(#)sys_term.c 8.4+1 (Berkeley) 5/30/95"; static char rcsid[] = "$NetBSD: sys_term.c,v 1.8 1996/02/28 20:38:21 thorpej Exp $"; #else -static char rcsid[] = "$OpenBSD: sys_term.c,v 1.18 1999/08/17 09:13:13 millert Exp $"; +static char rcsid[] = "$OpenBSD: sys_term.c,v 1.19 2000/09/15 07:13:47 deraadt Exp $"; #endif #endif /* not lint */ @@ -1644,10 +1644,10 @@ start_login(host, autologin, name) * real or kludge linemode. */ if (lmodetype == REAL_LINEMODE) - setenv("LINEMODE", "real", 1); + setenv("LINEMODE", "real", 1); /* XXX mem */ # ifdef KLUDGELINEMODE else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK) - setenv("LINEMODE", "kludge", 1); + setenv("LINEMODE", "kludge", 1); /* XXX mem */ # endif #endif #ifdef BFTPDAEMON diff --git a/libexec/telnetd/telnetd.c b/libexec/telnetd/telnetd.c index a6a7367a5ac..38055fb473e 100644 --- a/libexec/telnetd/telnetd.c +++ b/libexec/telnetd/telnetd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: telnetd.c,v 1.22 2000/08/18 03:26:10 itojun Exp $ */ +/* $OpenBSD: telnetd.c,v 1.23 2000/09/15 07:13:48 deraadt Exp $ */ /* $NetBSD: telnetd.c,v 1.6 1996/03/20 04:25:57 tls Exp $ */ /* @@ -45,7 +45,7 @@ static char copyright[] = static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; static char rcsid[] = "$NetBSD: telnetd.c,v 1.5 1996/02/28 20:38:23 thorpej Exp $"; #else -static char rcsid[] = "$OpenBSD: telnetd.c,v 1.22 2000/08/18 03:26:10 itojun Exp $"; +static char rcsid[] = "$OpenBSD: telnetd.c,v 1.23 2000/09/15 07:13:48 deraadt Exp $"; #endif #endif /* not lint */ @@ -907,7 +907,7 @@ doit(who) */ *user_name = 0; level = getterminaltype(user_name); - setenv("TERM", terminaltype ? terminaltype : "network", 1); + setenv("TERM", terminaltype ? terminaltype : "network", 1); /* XXX mem */ /* * Start up the login process on the slave side of the terminal diff --git a/usr.bin/env/env.1 b/usr.bin/env/env.1 index 2e24aaf0a31..5f1ac9f5531 100644 --- a/usr.bin/env/env.1 +++ b/usr.bin/env/env.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: env.1,v 1.6 2000/03/05 20:09:22 aaron Exp $ +.\" $OpenBSD: env.1,v 1.7 2000/09/15 07:13:48 deraadt Exp $ .\" Copyright (c) 1980, 1990 The Regents of the University of California. .\" All rights reserved. .\" @@ -96,9 +96,8 @@ The .Nm utility completed successfully. .It 1-125 -An error occurred in the -.Nm -utility. +The exit code returned from the +.Ar utility. .It 126 The utility specified by .Ar utility diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c index 087fbba09dc..2180a82617c 100644 --- a/usr.bin/env/env.c +++ b/usr.bin/env/env.c @@ -1,4 +1,4 @@ -/* $OpenBSD: env.c,v 1.4 1997/06/20 04:54:59 deraadt Exp $ */ +/* $OpenBSD: env.c,v 1.5 2000/09/15 07:13:48 deraadt Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -41,7 +41,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94";*/ -static char rcsid[] = "$OpenBSD: env.c,v 1.4 1997/06/20 04:54:59 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: env.c,v 1.5 2000/09/15 07:13:48 deraadt Exp $"; #endif /* not lint */ #include <err.h> @@ -52,7 +52,7 @@ static char rcsid[] = "$OpenBSD: env.c,v 1.4 1997/06/20 04:54:59 deraadt Exp $"; #include <locale.h> #include <errno.h> -static void usage __P((void)); +void usage __P((void)); int main(argc, argv) @@ -71,7 +71,7 @@ main(argc, argv) case '-': /* obsolete */ case 'i': if ((environ = (char **)calloc(1, sizeof(char *))) == NULL) - err(1, "calloc"); + err(126, "calloc"); break; case '?': default: @@ -79,12 +79,17 @@ main(argc, argv) } for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) - (void)setenv(*argv, ++p, 1); + if (setenv(*argv, ++p, 1) == -1) { + /* reuse 126, it matches the problem most */ + exit(126); + } if (*argv) { - /* return 127 if the command to be run could not be found; 126 - if the command was was found but could not be invoked */ - + /* + * return 127 if the command to be run could not be + * found; 126 if the command was found but could + * not be invoked + */ execvp(*argv, argv); err((errno == ENOENT) ? 127 : 126, "%s", *argv); /* NOTREACHED */ @@ -96,8 +101,8 @@ main(argc, argv) exit(0); } -static void -usage () +void +usage() { (void) fprintf(stderr, "usage: env [-i] [name=value ...] [command]\n"); exit (1); diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c index 4b6cc4e6e18..724c23f5624 100644 --- a/usr.bin/login/login.c +++ b/usr.bin/login/login.c @@ -1,4 +1,4 @@ -/* $OpenBSD: login.c,v 1.33 2000/09/04 19:15:27 millert Exp $ */ +/* $OpenBSD: login.c,v 1.34 2000/09/15 07:13:48 deraadt Exp $ */ /* $NetBSD: login.c,v 1.13 1996/05/15 23:50:16 jtc Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94"; #endif -static char rcsid[] = "$OpenBSD: login.c,v 1.33 2000/09/04 19:15:27 millert Exp $"; +static char rcsid[] = "$OpenBSD: login.c,v 1.34 2000/09/15 07:13:48 deraadt Exp $"; #endif /* not lint */ /* @@ -489,24 +489,46 @@ main(argc, argv) *cpp2 = 0; } /* Note: setusercontext(3) will set PATH */ - (void)setenv("HOME", pwd->pw_dir, 1); - (void)setenv("SHELL", shell, 1); + if (setenv("HOME", pwd->pw_dir, 1) == -1 || + setenv("SHELL", shell, 1) == -1) { + warn("unable to setenv()"); + exit(1); + } if (term[0] == '\0') (void)strlcpy(term, stypeof(tty), sizeof(term)); - (void)setenv("TERM", term, 0); - (void)setenv("LOGNAME", pwd->pw_name, 1); - (void)setenv("USER", pwd->pw_name, 1); - if (hostname) - (void)setenv("REMOTEHOST", hostname, 1); - if (rusername) - (void)setenv("REMOTEUSER", rusername, 1); + if (setenv("TERM", term, 0) == -1 || + setenv("LOGNAME", pwd->pw_name, 1) == -1 || + setenv("USER", pwd->pw_name, 1) == -1) { + warn("unable to setenv()"); + exit(1); + } + if (hostname) { + if (setenv("REMOTEHOST", hostname, 1) == -1) { + warn("unable to setenv()"); + exit(1); + } + } + if (rusername) { + if (setenv("REMOTEUSER", rusername, 1) == -1) { + warn("unable to setenv()"); + exit(1); + } + } #ifdef KERBEROS - if (krbtkfile_env) - (void)setenv("KRBTKFILE", krbtkfile_env, 1); + if (krbtkfile_env) { + if (setenv("KRBTKFILE", krbtkfile_env, 1) == -1) { + warn("unable to setenv()"); + exit(1); + } + } #endif #ifdef KERBEROS5 - if (krbtkfile_env) - (void)setenv("KRB5CCNAME", krbtkfile_env, 1); + if (krbtkfile_env) { + if (setenv("KRB5CCNAME", krbtkfile_env, 1) == -1) { + warn("unable to setenv()"); + exit(1); + } + } #endif /* If fflag is on, assume caller/authenticator has logged root login. */ if (rootlogin && fflag == 0) { diff --git a/usr.bin/ssh/ssh-agent.c b/usr.bin/ssh/ssh-agent.c index 5b178681f84..ecffb64b386 100644 --- a/usr.bin/ssh/ssh-agent.c +++ b/usr.bin/ssh/ssh-agent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-agent.c,v 1.35 2000/09/07 20:27:54 deraadt Exp $ */ +/* $OpenBSD: ssh-agent.c,v 1.36 2000/09/15 07:13:49 deraadt Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> @@ -37,7 +37,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-agent.c,v 1.35 2000/09/07 20:27:54 deraadt Exp $"); +RCSID("$OpenBSD: ssh-agent.c,v 1.36 2000/09/15 07:13:49 deraadt Exp $"); #include "ssh.h" #include "rsa.h" @@ -771,8 +771,11 @@ main(int ac, char **av) printf("echo Agent pid %d;\n", pid); exit(0); } - setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1); - setenv(SSH_AGENTPID_ENV_NAME, pidstrbuf, 1); + if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 || + setenv(SSH_AGENTPID_ENV_NAME, pidstrbuf, 1) == -1) { + perror("setenv"); + exit(1); + } execvp(av[0], av); perror(av[0]); exit(1); diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c index 63fa5a7ebba..0a0f67e7604 100644 --- a/usr.bin/su/su.c +++ b/usr.bin/su/su.c @@ -1,4 +1,4 @@ -/* $OpenBSD: su.c,v 1.33 2000/08/20 18:42:41 millert Exp $ */ +/* $OpenBSD: su.c,v 1.34 2000/09/15 07:13:50 deraadt Exp $ */ /* * Copyright (c) 1988 The Regents of the University of California. @@ -41,7 +41,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)su.c 5.26 (Berkeley) 7/6/91";*/ -static char rcsid[] = "$OpenBSD: su.c,v 1.33 2000/08/20 18:42:41 millert Exp $"; +static char rcsid[] = "$OpenBSD: su.c,v 1.34 2000/09/15 07:13:50 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -253,8 +253,10 @@ badlogin: errx(1, "calloc"); if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETPATH)) err(1, "unable to set user context"); - if (p) - (void)setenv("TERM", p, 1); + if (p) { + if (setenv("TERM", p, 1) == -1) + err(1, "unable to set environment"); + } seteuid(pwd->pw_uid); setegid(pwd->pw_gid); @@ -269,16 +271,20 @@ badlogin: err(1, "unable to set user context"); } if (asthem || pwd->pw_uid) { - (void)setenv("LOGNAME", pwd->pw_name, 1); - (void)setenv("USER", pwd->pw_name, 1); + if (setenv("LOGNAME", pwd->pw_name, 1) == -1 || + setenv("USER", pwd->pw_name, 1) == -1) + err(1, "unable to set environment"); } - (void)setenv("HOME", pwd->pw_dir, 1); - (void)setenv("SHELL", shell, 1); + if (setenv("HOME", pwd->pw_dir, 1) == -1 || + setenv("SHELL", shell, 1) == -1) + err(1, "unable to set environment"); } #ifdef KERBEROS - if (*krbtkfile) - (void)setenv("KRBTKFILE", krbtkfile, 1); + if (*krbtkfile) { + if (setenv("KRBTKFILE", krbtkfile, 1) == -1) + err(1, "unable to set environment"); + } #endif if (iscsh == YES) { diff --git a/usr.bin/vi/ex/ex_script.c b/usr.bin/vi/ex/ex_script.c index 9ca6d60060d..8a7cb472e4c 100644 --- a/usr.bin/vi/ex/ex_script.c +++ b/usr.bin/vi/ex/ex_script.c @@ -156,9 +156,10 @@ err: if (sc->sh_master != -1) * XXX * So that shells that do command line editing turn it off. */ - (void)setenv("TERM", "emacs", 1); - (void)setenv("TERMCAP", "emacs:", 1); - (void)setenv("EMACS", "t", 1); + if (setenv("TERM", "emacs", 1) == -1 || + setenv("TERMCAP", "emacs:", 1) == -1 || + setenv("EMACS", "t", 1) == -1) + _exit(126); (void)setsid(); #ifdef TIOCSCTTY diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c index 2302bde2a4c..19d7a9813af 100644 --- a/usr.sbin/cron/cron.c +++ b/usr.sbin/cron/cron.c @@ -16,7 +16,7 @@ */ #if !defined(lint) && !defined(LINT) -static char rcsid[] = "$Id: cron.c,v 1.7 2000/08/21 00:39:00 deraadt Exp $"; +static char rcsid[] = "$Id: cron.c,v 1.8 2000/09/15 07:13:50 deraadt Exp $"; #endif @@ -84,7 +84,10 @@ main(argc, argv) set_cron_cwd(); #if defined(POSIX) - setenv("PATH", _PATH_DEFPATH, 1); + if (setenv("PATH", _PATH_DEFPATH, 1) == -1) { + log_it("CRON",getpid(),"DEATH","can't malloc"); + exit(1); + } #endif /* if there are no debug flags turned on, fork as a daemon should. diff --git a/usr.sbin/pppd/main.c b/usr.sbin/pppd/main.c index f00e03fcfb9..323de618f0c 100644 --- a/usr.sbin/pppd/main.c +++ b/usr.sbin/pppd/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.28 2000/02/12 09:46:59 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.29 2000/09/15 07:13:51 deraadt Exp $ */ /* * main.c - Point-to-Point Protocol main module @@ -23,7 +23,7 @@ #if 0 static char rcsid[] = "Id: main.c,v 1.49 1998/05/05 05:24:17 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.28 2000/02/12 09:46:59 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.29 2000/09/15 07:13:51 deraadt Exp $"; #endif #endif @@ -1624,7 +1624,7 @@ script_setenv(var, value) newstring = (char *) malloc(vl + strlen(value) + 2); if (newstring == 0) - return; + novm("script_setenv"); strcpy(newstring, var); newstring[vl] = '='; strcpy(newstring+vl+1, value); @@ -1642,7 +1642,7 @@ script_setenv(var, value) i = 0; script_env = (char **) malloc(16 * sizeof(char *)); if (script_env == 0) - return; + novm("script_setenv"); s_env_nalloc = 16; } @@ -1652,7 +1652,7 @@ script_setenv(var, value) char **newenv = (char **) realloc((void *)script_env, new_n * sizeof(char *)); if (newenv == 0) - return; + novm("script_setenv"); script_env = newenv; s_env_nalloc = new_n; } |