diff options
| author | christos <christos@NetBSD.org> | 2014-09-18 13:58:20 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2014-09-18 13:58:20 +0000 |
| commit | 2c32905e1bfbd923da80f3b2b717ca983295f8ad (patch) | |
| tree | ee0132025875532ffa8e7e9480e8dece1419fde2 /lib/libc/gen | |
| parent | 658a9a8f623a74a2f8d0189494c4822ef512350a (diff) | |
make more descriptors that we open as close-on-exec
Diffstat (limited to 'lib/libc/gen')
| -rw-r--r-- | lib/libc/gen/fmtmsg.c | 6 | ||||
| -rw-r--r-- | lib/libc/gen/fts.c | 8 | ||||
| -rw-r--r-- | lib/libc/gen/getcap.c | 10 | ||||
| -rw-r--r-- | lib/libc/gen/getpass.c | 7 | ||||
| -rw-r--r-- | lib/libc/gen/nlist.c | 6 | ||||
| -rw-r--r-- | lib/libc/gen/syslog.c | 7 | ||||
| -rw-r--r-- | lib/libc/gen/utmpx.c | 16 |
7 files changed, 31 insertions, 29 deletions
diff --git a/lib/libc/gen/fmtmsg.c b/lib/libc/gen/fmtmsg.c index 5bd4c5f07cc..1fd683b37ee 100644 --- a/lib/libc/gen/fmtmsg.c +++ b/lib/libc/gen/fmtmsg.c @@ -1,4 +1,4 @@ -/* $NetBSD: fmtmsg.c,v 1.5 2012/03/20 16:36:05 matt Exp $ */ +/* $NetBSD: fmtmsg.c,v 1.6 2014/09/18 13:58:20 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fmtmsg.c,v 1.5 2012/03/20 16:36:05 matt Exp $"); +__RCSID("$NetBSD: fmtmsg.c,v 1.6 2014/09/18 13:58:20 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include <fmtmsg.h> @@ -213,7 +213,7 @@ fmtmsg(long classification, const char *label, int severity, } /* Similar to MM_PRINT but ignoring $MSGVERB. */ if (classification & MM_CONSOLE) { - if ((console = fopen(_PATH_CONSOLE, "w")) != NULL) { + if ((console = fopen(_PATH_CONSOLE, "we")) != NULL) { if (writeit(console, MM_VERBALL, label, sevstr, text, action, tag) < 0) result |= MM_NOCON; diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index d1236fd5fc9..2a492b91548 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -1,4 +1,4 @@ -/* $NetBSD: fts.c,v 1.46 2012/09/26 15:33:43 msaitoh Exp $ */ +/* $NetBSD: fts.c,v 1.47 2014/09/18 13:58:20 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; #else -__RCSID("$NetBSD: fts.c,v 1.46 2012/09/26 15:33:43 msaitoh Exp $"); +__RCSID("$NetBSD: fts.c,v 1.47 2014/09/18 13:58:20 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -601,7 +601,7 @@ fts_children(FTS *sp, int instr) ISSET(FTS_NOCHDIR)) return (sp->fts_child = fts_build(sp, instr)); - if ((fd = open(".", O_RDONLY, 0)) == -1) + if ((fd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) return (sp->fts_child = NULL); sp->fts_child = fts_build(sp, instr); if (fchdir(fd)) { @@ -1211,7 +1211,7 @@ fts_safe_changedir(const FTS *sp, const FTSENT *p, int fd, const char *path) if (ISSET(FTS_NOCHDIR)) return 0; - if (oldfd < 0 && (fd = open(path, O_RDONLY)) == -1) + if (oldfd < 0 && (fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) return -1; if (fstat(fd, &sb) == -1) diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index f7c25cad2b7..123704e5f39 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -1,4 +1,4 @@ -/* $NetBSD: getcap.c,v 1.53 2014/06/26 20:14:32 christos Exp $ */ +/* $NetBSD: getcap.c,v 1.54 2014/09/18 13:58:20 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #else -__RCSID("$NetBSD: getcap.c,v 1.53 2014/06/26 20:14:32 christos Exp $"); +__RCSID("$NetBSD: getcap.c,v 1.54 2014/09/18 13:58:20 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -322,8 +322,8 @@ getent(char **cap, size_t *len, const char * const *db_array, int fd, size_t clen; (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); - if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) - != NULL) { + if ((capdbp = dbopen(pbuf, O_RDONLY | O_CLOEXEC, 0, + DB_HASH, 0)) != NULL) { free(record); retval = cdbget(capdbp, &record, name); if (retval < 0) { @@ -352,7 +352,7 @@ getent(char **cap, size_t *len, const char * const *db_array, int fd, } else #endif { - fd = open(*db_p, O_RDONLY, 0); + fd = open(*db_p, O_RDONLY | O_CLOEXEC, 0); if (fd < 0) { /* No error on unfound file. */ continue; diff --git a/lib/libc/gen/getpass.c b/lib/libc/gen/getpass.c index 89a98e8946b..173d2860b85 100644 --- a/lib/libc/gen/getpass.c +++ b/lib/libc/gen/getpass.c @@ -1,4 +1,4 @@ -/* $NetBSD: getpass.c,v 1.28 2014/06/16 16:29:30 christos Exp $ */ +/* $NetBSD: getpass.c,v 1.29 2014/09/18 13:58:20 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getpass.c,v 1.28 2014/06/16 16:29:30 christos Exp $"); +__RCSID("$NetBSD: getpass.c,v 1.29 2014/09/18 13:58:20 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -107,7 +107,8 @@ getpassfd(const char *prompt, char *buf, size_t len, int *fd, int flags, * and write to stderr. */ fd = fdc; - if ((fd[0] = fd[1] = fd[2] = open(_PATH_TTY, O_RDWR)) == -1) { + if ((fd[0] = fd[1] = fd[2] = open(_PATH_TTY, + O_RDWR | O_CLOEXEC)) == -1) { fd[0] = STDIN_FILENO; fd[1] = fd[2] = STDERR_FILENO; } else diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c index ee229e02534..ec2531801b0 100644 --- a/lib/libc/gen/nlist.c +++ b/lib/libc/gen/nlist.c @@ -1,4 +1,4 @@ -/* $NetBSD: nlist.c,v 1.24 2012/03/21 15:32:26 christos Exp $ */ +/* $NetBSD: nlist.c,v 1.25 2014/09/18 13:58:20 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -66,7 +66,7 @@ #if 0 static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: nlist.c,v 1.24 2012/03/21 15:32:26 christos Exp $"); +__RCSID("$NetBSD: nlist.c,v 1.25 2014/09/18 13:58:20 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -119,7 +119,7 @@ nlist(const char *name, struct nlist *list) _DIAGASSERT(name != NULL); _DIAGASSERT(list != NULL); - fd = open(name, O_RDONLY, 0); + fd = open(name, O_RDONLY | O_CLOEXEC, 0); if (fd < 0) return (-1); n = __fdnlist(fd, list); diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 140c45040a6..beb898cb214 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -1,4 +1,4 @@ -/* $NetBSD: syslog.c,v 1.53 2012/10/11 17:09:55 christos Exp $ */ +/* $NetBSD: syslog.c,v 1.54 2014/09/18 13:58:20 christos Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)syslog.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: syslog.c,v 1.53 2012/10/11 17:09:55 christos Exp $"); +__RCSID("$NetBSD: syslog.c,v 1.54 2014/09/18 13:58:20 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -457,7 +457,8 @@ vsyslogp_r(int pri, struct syslog_data *data, const char *msgid, * Make sure the error reported is the one from the syslogd failure. */ if (tries == MAXTRIES && (data->log_stat & LOG_CONS) && - (fd = open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) { + (fd = open(_PATH_CONSOLE, + O_WRONLY | O_NONBLOCK | O_CLOEXEC, 0)) >= 0) { iov[iovcnt].iov_base = __UNCONST(CRLF); iov[iovcnt].iov_len = 2; (void)writev(fd, iov, iovcnt + 1); diff --git a/lib/libc/gen/utmpx.c b/lib/libc/gen/utmpx.c index 9476f33e833..5be2db0401c 100644 --- a/lib/libc/gen/utmpx.c +++ b/lib/libc/gen/utmpx.c @@ -1,4 +1,4 @@ -/* $NetBSD: utmpx.c,v 1.31 2013/09/05 17:35:11 pooka Exp $ */ +/* $NetBSD: utmpx.c,v 1.32 2014/09/18 13:58:20 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: utmpx.c,v 1.31 2013/09/05 17:35:11 pooka Exp $"); +__RCSID("$NetBSD: utmpx.c,v 1.32 2014/09/18 13:58:20 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -122,8 +122,8 @@ getutxent(void) struct stat st; if ((fp = fopen(utfile, "re+")) == NULL) - if ((fp = fopen(utfile, "w+")) == NULL) { - if ((fp = fopen(utfile, "r")) == NULL) + if ((fp = fopen(utfile, "we+")) == NULL) { + if ((fp = fopen(utfile, "re")) == NULL) goto fail; else readonly = 1; @@ -343,10 +343,10 @@ updwtmpx(const char *file, const struct utmpx *utx) _DIAGASSERT(file != NULL); _DIAGASSERT(utx != NULL); - fd = open(file, O_WRONLY|O_APPEND|O_SHLOCK); + fd = open(file, O_WRONLY|O_APPEND|O_SHLOCK|O_CLOEXEC); if (fd == -1) { - if ((fd = open(file, O_CREAT|O_WRONLY|O_EXLOCK, 0644)) == -1) + if ((fd = open(file, O_CREAT|O_WRONLY|O_EXLOCK|O_CLOEXEC, 0644)) == -1) return -1; (void)memset(&ut, 0, sizeof(ut)); ut.ut_type = SIGNATURE; @@ -432,7 +432,7 @@ getlastlogx(const char *fname, uid_t uid, struct lastlogx *ll) _DIAGASSERT(fname != NULL); _DIAGASSERT(ll != NULL); - db = dbopen(fname, O_RDONLY|O_SHLOCK, 0, DB_HASH, NULL); + db = dbopen(fname, O_RDONLY|O_SHLOCK|O_CLOEXEC, 0, DB_HASH, NULL); if (db == NULL) return NULL; @@ -471,7 +471,7 @@ updlastlogx(const char *fname, uid_t uid, struct lastlogx *ll) _DIAGASSERT(fname != NULL); _DIAGASSERT(ll != NULL); - db = dbopen(fname, O_RDWR|O_CREAT|O_EXLOCK, 0644, DB_HASH, NULL); + db = dbopen(fname, O_RDWR|O_CREAT|O_EXLOCK|O_CLOEXEC, 0644, DB_HASH, NULL); if (db == NULL) return -1; |
