diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2016-08-30 14:44:46 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2016-08-30 14:44:46 +0000 |
commit | cf19f8023d2f381cad286f58b3faf5d19fee29d4 (patch) | |
tree | 4f7ded012de4af64edb62811cefa3fbac4969b13 /lib | |
parent | 06a2db4962987663cb8b269b828429f88ad7f97d (diff) |
Use O_CLOEXEC when opening fds local to a function
ok jca@ krw@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libutil/logwtmp.c | 4 | ||||
-rw-r--r-- | lib/libutil/pty.c | 4 | ||||
-rw-r--r-- | lib/libutil/readlabel.c | 8 | ||||
-rw-r--r-- | lib/libutil/uucplock.c | 9 |
4 files changed, 13 insertions, 12 deletions
diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index 0f968c7679a..decde069377 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: logwtmp.c,v 1.9 2005/08/02 21:46:23 espie Exp $ */ +/* $OpenBSD: logwtmp.c,v 1.10 2016/08/30 14:44:45 guenther Exp $ */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -46,7 +46,7 @@ logwtmp(const char *line, const char *name, const char *host) struct utmp ut; int fd; - if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) + if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND|O_CLOEXEC)) < 0) return; if (fstat(fd, &buf) == 0) { (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line)); diff --git a/lib/libutil/pty.c b/lib/libutil/pty.c index 598b8fa1405..2a19de81ca5 100644 --- a/lib/libutil/pty.c +++ b/lib/libutil/pty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pty.c,v 1.19 2013/05/21 19:07:02 matthew Exp $ */ +/* $OpenBSD: pty.c,v 1.20 2016/08/30 14:44:45 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -54,7 +54,7 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp, * Use /dev/ptm and the PTMGET ioctl to get a properly set up and * owned pty/tty pair. */ - fd = open(PATH_PTMDEV, O_RDWR, 0); + fd = open(PATH_PTMDEV, O_RDWR|O_CLOEXEC); if (fd == -1) return (-1); if ((ioctl(fd, PTMGET, &ptm) == -1)) { diff --git a/lib/libutil/readlabel.c b/lib/libutil/readlabel.c index e2cee311d28..d53820e67ac 100644 --- a/lib/libutil/readlabel.c +++ b/lib/libutil/readlabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readlabel.c,v 1.13 2015/01/16 16:48:52 deraadt Exp $ */ +/* $OpenBSD: readlabel.c,v 1.14 2016/08/30 14:44:45 guenther Exp $ */ /* * Copyright (c) 1996, Jason Downs. All rights reserved. @@ -59,7 +59,7 @@ readlabelfs(char *device, int verbose) /* Perform disk mapping if device is given as a DUID. */ if (isduid(device, 0)) { - if ((fd = open("/dev/diskmap", O_RDONLY)) != -1) { + if ((fd = open("/dev/diskmap", O_RDONLY|O_CLOEXEC)) != -1) { bzero(&dm, sizeof(struct dk_diskmap)); strlcpy(rpath, device, sizeof(rpath)); part = rpath[strlen(rpath) - 1]; @@ -105,12 +105,12 @@ readlabelfs(char *device, int verbose) } /* If rpath doesn't exist, change that partition back. */ - fd = open(rpath, O_RDONLY); + fd = open(rpath, O_RDONLY|O_CLOEXEC); if (fd < 0) { if (errno == ENOENT) { rpath[strlen(rpath) - 1] = part; - fd = open(rpath, O_RDONLY); + fd = open(rpath, O_RDONLY|O_CLOEXEC); if (fd < 0) { if (verbose) warn("%s", rpath); diff --git a/lib/libutil/uucplock.c b/lib/libutil/uucplock.c index f62273c8f9f..bf63f775b34 100644 --- a/lib/libutil/uucplock.c +++ b/lib/libutil/uucplock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uucplock.c,v 1.17 2015/11/11 01:12:09 deraadt Exp $ */ +/* $OpenBSD: uucplock.c,v 1.18 2016/08/30 14:44:45 guenther Exp $ */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -70,7 +70,8 @@ uu_lock(const char *ttyname) (long)pid); (void)snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, ttyname); - if ((tmpfd = open(lcktmpname, O_CREAT | O_TRUNC | O_WRONLY, 0664)) < 0) + tmpfd = open(lcktmpname, O_CREAT|O_TRUNC|O_WRONLY|O_CLOEXEC, 0664); + if (tmpfd < 0) GORET(0, UU_LOCK_CREAT_ERR); for (i = 0; i < MAXTRIES; i++) { @@ -82,7 +83,7 @@ uu_lock(const char *ttyname) * check to see if the process holding the lock * still exists */ - if ((fd = open(lckname, O_RDONLY)) < 0) + if ((fd = open(lckname, O_RDONLY | O_CLOEXEC)) < 0) GORET(1, UU_LOCK_OPEN_ERR); if ((pid_old = get_pid(fd, &err)) == -1) @@ -126,7 +127,7 @@ uu_lock_txfr(const char *ttyname, pid_t pid) snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, ttyname); - if ((fd = open(lckname, O_RDWR)) < 0) + if ((fd = open(lckname, O_RDWR | O_CLOEXEC)) < 0) return UU_LOCK_OWNER_ERR; if (get_pid(fd, &err) != getpid()) ret = UU_LOCK_OWNER_ERR; |