Browse Source

Use O_CLOEXEC when opening fds local to a function

ok jca@ krw@
OPENBSD_6_1
guenther 8 years ago
parent
commit
98ac59d5a1
4 changed files with 13 additions and 12 deletions
  1. +2
    -2
      src/lib/libutil/logwtmp.c
  2. +2
    -2
      src/lib/libutil/pty.c
  3. +4
    -4
      src/lib/libutil/readlabel.c
  4. +5
    -4
      src/lib/libutil/uucplock.c

+ 2
- 2
src/lib/libutil/logwtmp.c View File

@ -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));


+ 2
- 2
src/lib/libutil/pty.c View File

@ -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)) {


+ 4
- 4
src/lib/libutil/readlabel.c View File

@ -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);


+ 5
- 4
src/lib/libutil/uucplock.c View File

@ -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;


Loading…
Cancel
Save