diff options
author | 2004-01-23 03:48:42 +0000 | |
---|---|---|
committer | 2004-01-23 03:48:42 +0000 | |
commit | 188b81b301363fd0ed80a91d62e6e2e65b573c69 (patch) | |
tree | ee108d88fd789bd32ed57a01646e57a5d28ae80c | |
parent | Don't probe impossible luns. If lun 0 is non-existant, or if the device shows (diff) | |
download | wireguard-openbsd-188b81b301363fd0ed80a91d62e6e2e65b573c69.tar.xz wireguard-openbsd-188b81b301363fd0ed80a91d62e6e2e65b573c69.zip |
Use closefrom(); ok millert tedu
-rw-r--r-- | lib/libc/gen/auth_subr.c | 6 | ||||
-rw-r--r-- | usr.bin/login/login.c | 10 | ||||
-rw-r--r-- | usr.bin/sup/src/supcmain.c | 5 | ||||
-rw-r--r-- | usr.bin/sup/src/supfilesrv.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp/bundle.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp/chap.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp/command.c | 3 | ||||
-rw-r--r-- | usr.sbin/rbootd/rbootd.c | 13 | ||||
-rw-r--r-- | usr.sbin/sliplogin/sliplogin.c | 6 | ||||
-rw-r--r-- | usr.sbin/ypserv/ypserv/ypserv.c | 8 |
10 files changed, 25 insertions, 41 deletions
diff --git a/lib/libc/gen/auth_subr.c b/lib/libc/gen/auth_subr.c index 087c524a105..92fb6706de1 100644 --- a/lib/libc/gen/auth_subr.c +++ b/lib/libc/gen/auth_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth_subr.c,v 1.25 2004/01/10 16:45:56 millert Exp $ */ +/* $OpenBSD: auth_subr.c,v 1.26 2004/01/23 03:48:42 deraadt Exp $ */ /*- * Copyright (c) 1995,1996,1997 Berkeley Software Design, Inc. @@ -827,9 +827,7 @@ auth_call(auth_session_t *as, char *path, ...) close(pfd[1]); } - for (status = getdtablesize() - 1; status > COMM_FD; status--) - close(status); - + closefrom(COMM_FD + 1); execve(path, argv, auth_environ); syslog(LOG_ERR, "%s: %m", path); err(1, "%s", path); diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c index 95eb83098a3..1481bf2c085 100644 --- a/usr.bin/login/login.c +++ b/usr.bin/login/login.c @@ -1,4 +1,4 @@ -/* $OpenBSD: login.c,v 1.52 2003/11/09 20:13:57 otto Exp $ */ +/* $OpenBSD: login.c,v 1.53 2004/01/23 03:48:43 deraadt Exp $ */ /* $NetBSD: login.c,v 1.13 1996/05/15 23:50:16 jtc Exp $ */ /*- @@ -73,7 +73,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94"; #endif -static const char rcsid[] = "$OpenBSD: login.c,v 1.52 2003/11/09 20:13:57 otto Exp $"; +static const char rcsid[] = "$OpenBSD: login.c,v 1.53 2004/01/23 03:48:43 deraadt Exp $"; #endif /* not lint */ /* @@ -276,8 +276,7 @@ main(int argc, char *argv[]) } else ask = 1; - for (cnt = getdtablesize(); cnt > 2; cnt--) - (void)close(cnt); + closefrom(3); /* * If effective user is not root, just run su(1) to emulate login(1). @@ -759,8 +758,7 @@ failed: * Assume that stdin, stdout and stderr are 0, 1 and 2, and that * STDERR_FILENO is 2. */ - for (cnt = getdtablesize(); cnt > STDERR_FILENO; cnt--) - (void)close(cnt); + closefrom(STDERR_FILENO + 1); /* * Close the authentication session, make sure it is marked diff --git a/usr.bin/sup/src/supcmain.c b/usr.bin/sup/src/supcmain.c index bd41e56dc72..099bdcddccb 100644 --- a/usr.bin/sup/src/supcmain.c +++ b/usr.bin/sup/src/supcmain.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supcmain.c,v 1.17 2002/12/09 00:45:38 millert Exp $ */ +/* $OpenBSD: supcmain.c,v 1.18 2004/01/23 03:48:43 deraadt Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -417,8 +417,7 @@ main(argc, argv) if (!silent) loginfo("SUP Restarting %s with new supfile %s", progname, supfname); - for (fd = getdtablesize(); fd > 3; fd--) - (void) close(fd); + closefrom(4); execv(progname, argv); logquit(1, "Restart failed"); } diff --git a/usr.bin/sup/src/supfilesrv.c b/usr.bin/sup/src/supfilesrv.c index c1974335326..e7cbc03fac4 100644 --- a/usr.bin/sup/src/supfilesrv.c +++ b/usr.bin/sup/src/supfilesrv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supfilesrv.c,v 1.32 2003/09/04 03:24:07 beck Exp $ */ +/* $OpenBSD: supfilesrv.c,v 1.33 2004/01/23 03:48:43 deraadt Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -751,9 +751,7 @@ answer() (void) dup2(netfile,0); (void) dup2(netfile,1); (void) dup2(netfile,2); - fd = getdtablesize(); - while (--fd > 2) - (void) close(fd); + closefrom(3); execvp(xargv[0], xargv); exit(0); } diff --git a/usr.sbin/ppp/ppp/bundle.c b/usr.sbin/ppp/ppp/bundle.c index 0d3d8307fc8..136943f2b1e 100644 --- a/usr.sbin/ppp/ppp/bundle.c +++ b/usr.sbin/ppp/ppp/bundle.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: bundle.c,v 1.67 2003/04/04 20:25:06 deraadt Exp $ + * $OpenBSD: bundle.c,v 1.68 2004/01/23 03:48:43 deraadt Exp $ */ #include <sys/param.h> @@ -1791,8 +1791,8 @@ bundle_setsid(struct bundle *bundle, int holdsession) signal(SIGTERM, SIG_DFL); signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); - for (fd = getdtablesize(); fd >= 0; fd--) - close(fd); + closefrom(0); + /* * Reap the intermediate process. As we're not exiting but the * intermediate is, we don't want it to become defunct. diff --git a/usr.sbin/ppp/ppp/chap.c b/usr.sbin/ppp/ppp/chap.c index 0e56d899b48..fe54e64f477 100644 --- a/usr.sbin/ppp/ppp/chap.c +++ b/usr.sbin/ppp/ppp/chap.c @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: chap.c,v 1.39 2003/04/08 19:55:52 tedu Exp $ + * $OpenBSD: chap.c,v 1.40 2004/01/23 03:48:43 deraadt Exp $ */ #include <sys/param.h> @@ -309,6 +309,7 @@ chap_StartChild(struct chap *chap, char *prog, const char *name) _PATH_DEVNULL, strerror(errno)); exit(1); } + /* XXX using an fwalk()-like thing would be safer */ for (fd = getdtablesize(); fd > STDERR_FILENO; fd--) fcntl(fd, F_SETFD, 1); #ifndef NOSUID diff --git a/usr.sbin/ppp/ppp/command.c b/usr.sbin/ppp/ppp/command.c index 9f010d3e7db..aa32156469a 100644 --- a/usr.sbin/ppp/ppp/command.c +++ b/usr.sbin/ppp/ppp/command.c @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: command.c,v 1.78 2003/04/04 20:28:57 deraadt Exp $ + * $OpenBSD: command.c,v 1.79 2004/01/23 03:48:43 deraadt Exp $ */ #include <sys/param.h> @@ -638,6 +638,7 @@ ShellCommand(struct cmdargs const *arg, int bg) dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); +/* fwalk */ for (i = getdtablesize(); i > STDERR_FILENO; i--) fcntl(i, F_SETFD, 1); diff --git a/usr.sbin/rbootd/rbootd.c b/usr.sbin/rbootd/rbootd.c index 544bbc971f8..9b604e88b47 100644 --- a/usr.sbin/rbootd/rbootd.c +++ b/usr.sbin/rbootd/rbootd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rbootd.c,v 1.18 2003/06/27 22:34:25 deraadt Exp $ */ +/* $OpenBSD: rbootd.c,v 1.19 2004/01/23 03:48:43 deraadt Exp $ */ /* $NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $ */ /* @@ -51,7 +51,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "@(#)rbootd.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$OpenBSD: rbootd.c,v 1.18 2003/06/27 22:34:25 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: rbootd.c,v 1.19 2004/01/23 03:48:43 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -101,14 +101,7 @@ main(int argc, char *argv[]) * Temporarily leave stdin & stdout open for `-d', * and stderr open for any pre-syslog error messages. */ - { - int i, nfds = getdtablesize(); - - for (i = 0; i < nfds; i++) - if (i != fileno(stdin) && i != fileno(stdout) && - i != fileno(stderr)) - (void) close(i); - } + closefrom(STDERR_FILENO + 1); /* * Parse any arguments. diff --git a/usr.sbin/sliplogin/sliplogin.c b/usr.sbin/sliplogin/sliplogin.c index 961631ba0de..3b874127a7a 100644 --- a/usr.sbin/sliplogin/sliplogin.c +++ b/usr.sbin/sliplogin/sliplogin.c @@ -35,7 +35,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)sliplogin.c 5.6 (Berkeley) 3/2/91";*/ -static char rcsid[] = "$Id: sliplogin.c,v 1.23 2003/06/26 21:36:39 deraadt Exp $"; +static char rcsid[] = "$Id: sliplogin.c,v 1.24 2004/01/23 03:48:43 deraadt Exp $"; #endif /* not lint */ /* @@ -193,9 +193,7 @@ main(int argc, char *argv[]) name = argv[0]; else name++; - s = getdtablesize(); - for (fd = 3 ; fd < s ; fd++) - (void) close(fd); + closefrom(3); if (argc > 1 && strlen(argv[1]) > MAXLOGNAME) errx(1, "login %s too long", argv[1]); openlog(name, LOG_PID, LOG_DAEMON); diff --git a/usr.sbin/ypserv/ypserv/ypserv.c b/usr.sbin/ypserv/ypserv/ypserv.c index c7528bb7bb8..c3903712102 100644 --- a/usr.sbin/ypserv/ypserv/ypserv.c +++ b/usr.sbin/ypserv/ypserv/ypserv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypserv.c,v 1.31 2003/07/15 06:10:46 deraadt Exp $ */ +/* $OpenBSD: ypserv.c,v 1.32 2004/01/23 03:48:43 deraadt Exp $ */ /* * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se> @@ -27,7 +27,7 @@ */ #ifndef LINT -static const char rcsid[] = "$OpenBSD: ypserv.c,v 1.31 2003/07/15 06:10:46 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: ypserv.c,v 1.32 2004/01/23 03:48:43 deraadt Exp $"; #endif #include <sys/types.h> @@ -456,9 +456,7 @@ main(int argc, char *argv[]) } if (pid) exit(0); - size = getdtablesize(); - for (i = 0; i < size; i++) - (void) close(i); + closefrom(0); i = open("/dev/console", 2); (void) dup2(i, 1); (void) dup2(i, 2); |