Skip to content

Commit

Permalink
For open/openat, if the flags parameter does not contain O_CREAT, the
Browse files Browse the repository at this point in the history
3rd (variadic) mode_t parameter is irrelevant.  Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk.  They could all be 0xdeafbeef.
ok millert
  • Loading branch information
deraadt committed Oct 24, 2021
1 parent 4f56c6f commit b7041c0
Show file tree
Hide file tree
Showing 133 changed files with 307 additions and 307 deletions.
4 changes: 2 additions & 2 deletions bin/cat/cat.c
@@ -1,4 +1,4 @@
/* $OpenBSD: cat.c,v 1.31 2020/12/11 05:48:22 cheloha Exp $ */
/* $OpenBSD: cat.c,v 1.32 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: cat.c,v 1.11 1995/09/07 06:12:54 jtc Exp $ */

/*
Expand Down Expand Up @@ -208,7 +208,7 @@ raw_args(char **argv)
raw_cat(fileno(stdin), "stdin");
continue;
}
if ((fd = open(*argv, O_RDONLY, 0)) == -1) {
if ((fd = open(*argv, O_RDONLY)) == -1) {
warn("%s", *argv);
rval = 1;
continue;
Expand Down
4 changes: 2 additions & 2 deletions bin/chio/chio.c
@@ -1,4 +1,4 @@
/* $OpenBSD: chio.c,v 1.28 2021/08/31 05:29:55 robert Exp $ */
/* $OpenBSD: chio.c,v 1.29 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: chio.c,v 1.1.1.1 1996/04/03 00:34:38 thorpej Exp $ */

/*
Expand Down Expand Up @@ -134,7 +134,7 @@ main(int argc, char *argv[])
changer_name = _PATH_CH;

/* Open the changer device. */
if ((changer_fd = open(changer_name, O_RDWR, 0600)) == -1)
if ((changer_fd = open(changer_name, O_RDWR)) == -1)
err(1, "%s: open", changer_name);

/* Find the specified command. */
Expand Down
6 changes: 3 additions & 3 deletions bin/cp/utils.c
@@ -1,4 +1,4 @@
/* $OpenBSD: utils.c,v 1.48 2019/06/28 13:34:58 deraadt Exp $ */
/* $OpenBSD: utils.c,v 1.49 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */

/*-
Expand Down Expand Up @@ -71,7 +71,7 @@ copy_file(FTSENT *entp, int exists)
err(1, "calloc");
}

if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
if ((from_fd = open(entp->fts_path, O_RDONLY)) == -1) {
warn("%s", entp->fts_path);
return (1);
}
Expand All @@ -97,7 +97,7 @@ copy_file(FTSENT *entp, int exists)
(void)close(from_fd);
return 2;
}
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
to_fd = open(to.p_path, O_WRONLY | O_TRUNC);
} else
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
fs->st_mode & ~(S_ISTXT | S_ISUID | S_ISGID));
Expand Down
4 changes: 2 additions & 2 deletions bin/dd/dd.c
@@ -1,4 +1,4 @@
/* $OpenBSD: dd.c,v 1.27 2019/06/28 13:34:59 deraadt Exp $ */
/* $OpenBSD: dd.c,v 1.28 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: dd.c,v 1.6 1996/02/20 19:29:06 jtc Exp $ */

/*-
Expand Down Expand Up @@ -95,7 +95,7 @@ setup(void)
in.name = "stdin";
in.fd = STDIN_FILENO;
} else {
in.fd = open(in.name, O_RDONLY, 0);
in.fd = open(in.name, O_RDONLY);
if (in.fd == -1)
err(1, "%s", in.name);
}
Expand Down
4 changes: 2 additions & 2 deletions bin/ksh/exec.c
@@ -1,4 +1,4 @@
/* $OpenBSD: exec.c,v 1.74 2019/06/28 13:34:59 deraadt Exp $ */
/* $OpenBSD: exec.c,v 1.75 2021/10/24 21:24:21 deraadt Exp $ */

/*
* execute command tree
Expand Down Expand Up @@ -1197,7 +1197,7 @@ herein(const char *content, int sub)
* doesn't get removed too soon).
*/
h = maketemp(ATEMP, TT_HEREDOC_EXP, &genv->temps);
if (!(shf = h->shf) || (fd = open(h->name, O_RDONLY, 0)) == -1) {
if (!(shf = h->shf) || (fd = open(h->name, O_RDONLY)) == -1) {
warningf(true, "can't %s temporary file %s: %s",
!shf ? "create" : "open",
h->name, strerror(errno));
Expand Down
4 changes: 2 additions & 2 deletions bin/ksh/tty.c
@@ -1,4 +1,4 @@
/* $OpenBSD: tty.c,v 1.18 2019/06/28 13:34:59 deraadt Exp $ */
/* $OpenBSD: tty.c,v 1.19 2021/10/24 21:24:21 deraadt Exp $ */

#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -33,7 +33,7 @@ tty_init(int init_ttystate)
tty_close();
tty_devtty = 1;

tfd = open("/dev/tty", O_RDWR, 0);
tfd = open("/dev/tty", O_RDWR);
if (tfd == -1) {
tty_devtty = 0;
warningf(false, "No controlling tty (open /dev/tty: %s)",
Expand Down
8 changes: 4 additions & 4 deletions bin/mv/cp.c
@@ -1,4 +1,4 @@
/* $OpenBSD: cp.c,v 1.8 2019/06/28 13:34:59 deraadt Exp $ */
/* $OpenBSD: cp.c,v 1.9 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: cp.c,v 1.14 1995/09/07 06:14:51 jtc Exp $ */

/*
Expand Down Expand Up @@ -386,7 +386,7 @@ copy(char *argv[], enum op type, int fts_options)
}


/* $OpenBSD: cp.c,v 1.8 2019/06/28 13:34:59 deraadt Exp $ */
/* $OpenBSD: cp.c,v 1.9 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */

/*-
Expand Down Expand Up @@ -455,7 +455,7 @@ copy_file(FTSENT *entp, int dne)
err(1, "calloc");
}

if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
if ((from_fd = open(entp->fts_path, O_RDONLY)) == -1) {
warn("%s", entp->fts_path);
return (1);
}
Expand Down Expand Up @@ -488,7 +488,7 @@ copy_file(FTSENT *entp, int dne)
return (0);
}
}
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
to_fd = open(to.p_path, O_WRONLY | O_TRUNC);
} else
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
fs->st_mode & ~(S_ISTXT | S_ISUID | S_ISGID));
Expand Down
4 changes: 2 additions & 2 deletions bin/mv/mv.c
@@ -1,4 +1,4 @@
/* $OpenBSD: mv.c,v 1.46 2019/06/28 13:34:59 deraadt Exp $ */
/* $OpenBSD: mv.c,v 1.47 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: mv.c,v 1.9 1995/03/21 09:06:52 cgd Exp $ */

/*
Expand Down Expand Up @@ -276,7 +276,7 @@ fastcopy(char *from, char *to, struct stat *sbp)
}
}

if ((from_fd = open(from, O_RDONLY, 0)) == -1) {
if ((from_fd = open(from, O_RDONLY)) == -1) {
warn("%s", from);
return (1);
}
Expand Down
6 changes: 3 additions & 3 deletions bin/pax/ar_subs.c
@@ -1,4 +1,4 @@
/* $OpenBSD: ar_subs.c,v 1.49 2019/06/28 13:34:59 deraadt Exp $ */
/* $OpenBSD: ar_subs.c,v 1.50 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: ar_subs.c,v 1.5 1995/03/21 09:07:06 cgd Exp $ */

/*-
Expand Down Expand Up @@ -448,7 +448,7 @@ wr_archive(ARCHD *arcn, int is_app)
* we were later unable to read (we also purge it from
* the link table).
*/
if ((fd = open(arcn->org_name, O_RDONLY, 0)) < 0) {
if ((fd = open(arcn->org_name, O_RDONLY)) < 0) {
syswarn(1,errno, "Unable to open %s to read",
arcn->org_name);
purg_lnk(arcn);
Expand Down Expand Up @@ -918,7 +918,7 @@ copy(void)
* have to copy a regular file to the destination directory.
* first open source file and then create the destination file
*/
if ((fdsrc = open(arcn->org_name, O_RDONLY, 0)) < 0) {
if ((fdsrc = open(arcn->org_name, O_RDONLY)) < 0) {
syswarn(1, errno, "Unable to open %s to read",
arcn->org_name);
purg_lnk(arcn);
Expand Down
4 changes: 2 additions & 2 deletions bin/rm/rm.c
@@ -1,4 +1,4 @@
/* $OpenBSD: rm.c,v 1.42 2017/06/27 21:49:47 tedu Exp $ */
/* $OpenBSD: rm.c,v 1.43 2021/10/24 21:24:21 deraadt Exp $ */
/* $NetBSD: rm.c,v 1.19 1995/09/07 06:48:50 jtc Exp $ */

/*-
Expand Down Expand Up @@ -310,7 +310,7 @@ rm_overwrite(char *file, struct stat *sbp)
file, (unsigned long long)sbp->st_ino);
return (0);
}
if ((fd = open(file, O_WRONLY|O_NONBLOCK|O_NOFOLLOW, 0)) == -1)
if ((fd = open(file, O_WRONLY|O_NONBLOCK|O_NOFOLLOW)) == -1)
goto err;
if (fstat(fd, &sb2))
goto err;
Expand Down
4 changes: 2 additions & 2 deletions lib/libc/gen/authenticate.c
@@ -1,4 +1,4 @@
/* $OpenBSD: authenticate.c,v 1.28 2019/12/04 06:25:45 deraadt Exp $ */
/* $OpenBSD: authenticate.c,v 1.29 2021/10/24 21:24:20 deraadt Exp $ */

/*-
* Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
Expand Down Expand Up @@ -164,7 +164,7 @@ auth_cat(char *file)
int fd, nchars;
char tbuf[8192];

if ((fd = open(file, O_RDONLY, 0)) == -1)
if ((fd = open(file, O_RDONLY)) == -1)
return (0);
while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
(void)write(fileno(stdout), tbuf, nchars);
Expand Down
4 changes: 2 additions & 2 deletions lib/libc/gen/daemon.c
@@ -1,4 +1,4 @@
/* $OpenBSD: daemon.c,v 1.7 2010/07/27 22:29:09 marco Exp $ */
/* $OpenBSD: daemon.c,v 1.8 2021/10/24 21:24:20 deraadt Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
Expand Down Expand Up @@ -53,7 +53,7 @@ daemon(int nochdir, int noclose)
if (!nochdir)
(void)chdir("/");

if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR)) != -1) {
(void)dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO);
Expand Down
10 changes: 5 additions & 5 deletions lib/libc/gen/err.3
@@ -1,4 +1,4 @@
.\" $OpenBSD: err.3,v 1.21 2019/05/16 13:35:16 schwarze Exp $
.\" $OpenBSD: err.3,v 1.22 2021/10/24 21:24:20 deraadt Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
Expand Down Expand Up @@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: May 16 2019 $
.Dd $Mdocdate: October 24 2021 $
.Dt ERR 3
.Os
.Sh NAME
Expand Down Expand Up @@ -166,7 +166,7 @@ information string and exit:
.Bd -literal -offset indent
if ((p = malloc(size)) == NULL)
err(1, NULL);
if ((fd = open(file_name, O_RDONLY, 0)) == -1)
if ((fd = open(file_name, O_RDONLY)) == -1)
err(1, "%s", file_name);
.Ed
.Pp
Expand All @@ -178,10 +178,10 @@ if (tm.tm_hour < START_TIME)
.Pp
Warn of an error:
.Bd -literal -offset indent
if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
if ((fd = open(raw_device, O_RDONLY)) == -1)
warnx("%s: %s: trying the block device",
raw_device, strerror(errno));
if ((fd = open(block_device, O_RDONLY, 0)) == -1)
if ((fd = open(block_device, O_RDONLY)) == -1)
err(1, "%s", block_device);
.Ed
.Sh SEE ALSO
Expand Down
6 changes: 3 additions & 3 deletions lib/libc/stdlib/getopt.3
Expand Up @@ -25,9 +25,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $OpenBSD: getopt.3,v 1.46 2016/01/04 19:43:13 tb Exp $
.\" $OpenBSD: getopt.3,v 1.47 2021/10/24 21:24:20 deraadt Exp $
.\"
.Dd $Mdocdate: January 4 2016 $
.Dd $Mdocdate: October 24 2021 $
.Dt GETOPT 3
.Os
.Sh NAME
Expand Down Expand Up @@ -178,7 +178,7 @@ while ((ch = getopt(argc, argv, "bf:")) != -1) {
bflag = 1;
break;
case 'f':
if ((fd = open(optarg, O_RDONLY, 0)) == -1)
if ((fd = open(optarg, O_RDONLY)) == -1)
err(1, "%s", optarg);
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions lib/libc/stdlib/getopt_long.3
@@ -1,4 +1,4 @@
.\" $OpenBSD: getopt_long.3,v 1.22 2020/01/13 18:05:10 stsp Exp $
.\" $OpenBSD: getopt_long.3,v 1.23 2021/10/24 21:24:20 deraadt Exp $
.\" $NetBSD: getopt_long.3,v 1.11 2002/10/02 10:54:19 wiz Exp $
.\"
.\" Copyright (c) 1988, 1991, 1993
Expand Down Expand Up @@ -30,7 +30,7 @@
.\"
.\" @(#)getopt.3 8.5 (Berkeley) 4/27/95
.\"
.Dd $Mdocdate: January 13 2020 $
.Dd $Mdocdate: October 24 2021 $
.Dt GETOPT_LONG 3
.Os
.Sh NAME
Expand Down Expand Up @@ -426,7 +426,7 @@ while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1)
bflag = 1;
break;
case 'f':
if ((fd = open(optarg, O_RDONLY, 0)) == -1)
if ((fd = open(optarg, O_RDONLY)) == -1)
err(1, "unable to open %s", optarg);
break;
case 0:
Expand Down
4 changes: 2 additions & 2 deletions lib/libcrypto/arc4random/getentropy_aix.c
@@ -1,4 +1,4 @@
/* $OpenBSD: getentropy_aix.c,v 1.7 2020/05/17 14:44:20 deraadt Exp $ */
/* $OpenBSD: getentropy_aix.c,v 1.8 2021/10/24 21:24:20 deraadt Exp $ */

/*
* Copyright (c) 2015 Michael Felt <aixtools@gmail.com>
Expand Down Expand Up @@ -134,7 +134,7 @@ getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck)
#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
fd = open(path, flags, 0);
fd = open(path, flags);
if (fd == -1) {
if (errno == EINTR)
goto start;
Expand Down
4 changes: 2 additions & 2 deletions lib/libcrypto/arc4random/getentropy_hpux.c
@@ -1,4 +1,4 @@
/* $OpenBSD: getentropy_hpux.c,v 1.7 2020/05/17 14:44:20 deraadt Exp $ */
/* $OpenBSD: getentropy_hpux.c,v 1.8 2021/10/24 21:24:20 deraadt Exp $ */

/*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
Expand Down Expand Up @@ -138,7 +138,7 @@ getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck)
#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
fd = open(path, flags, 0);
fd = open(path, flags);
if (fd == -1) {
if (errno == EINTR)
goto start;
Expand Down
4 changes: 2 additions & 2 deletions lib/libcrypto/arc4random/getentropy_linux.c
@@ -1,4 +1,4 @@
/* $OpenBSD: getentropy_linux.c,v 1.47 2020/05/17 14:44:20 deraadt Exp $ */
/* $OpenBSD: getentropy_linux.c,v 1.48 2021/10/24 21:24:20 deraadt Exp $ */

/*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
Expand Down Expand Up @@ -212,7 +212,7 @@ getentropy_urandom(void *buf, size_t len)
#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
fd = open("/dev/urandom", flags, 0);
fd = open("/dev/urandom", flags);
if (fd == -1) {
if (errno == EINTR)
goto start;
Expand Down
4 changes: 2 additions & 2 deletions lib/libcrypto/arc4random/getentropy_osx.c
@@ -1,4 +1,4 @@
/* $OpenBSD: getentropy_osx.c,v 1.13 2020/05/17 14:44:20 deraadt Exp $ */
/* $OpenBSD: getentropy_osx.c,v 1.14 2021/10/24 21:24:20 deraadt Exp $ */

/*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
Expand Down Expand Up @@ -158,7 +158,7 @@ getentropy_urandom(void *buf, size_t len)
#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
fd = open("/dev/urandom", flags, 0);
fd = open("/dev/urandom", flags);
if (fd == -1) {
if (errno == EINTR)
goto start;
Expand Down
4 changes: 2 additions & 2 deletions lib/libcrypto/arc4random/getentropy_solaris.c
@@ -1,4 +1,4 @@
/* $OpenBSD: getentropy_solaris.c,v 1.14 2020/05/17 14:44:20 deraadt Exp $ */
/* $OpenBSD: getentropy_solaris.c,v 1.15 2021/10/24 21:24:20 deraadt Exp $ */

/*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
Expand Down Expand Up @@ -164,7 +164,7 @@ getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck)
#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
fd = open(path, flags, 0);
fd = open(path, flags);
if (fd == -1) {
if (errno == EINTR)
goto start;
Expand Down
6 changes: 3 additions & 3 deletions lib/libcurses/tinfo/read_termcap.c
@@ -1,4 +1,4 @@
/* $OpenBSD: read_termcap.c,v 1.22 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: read_termcap.c,v 1.23 2021/10/24 21:24:20 deraadt Exp $ */

/****************************************************************************
* Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
Expand Down Expand Up @@ -60,7 +60,7 @@
#include <tic.h>
#include <term_entry.h>

MODULE_ID("$Id: read_termcap.c,v 1.22 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: read_termcap.c,v 1.23 2021/10/24 21:24:20 deraadt Exp $")

#if !PURE_TERMINFO

Expand Down Expand Up @@ -316,7 +316,7 @@ _nc_getent(
if (fd >= 0) {
(void) lseek(fd, (off_t) 0, SEEK_SET);
} else if ((_nc_access(db_array[current], R_OK) < 0)
|| (fd = open(db_array[current], O_RDONLY, 0)) < 0) {
|| (fd = open(db_array[current], O_RDONLY)) < 0) {
/* No error on unfound file. */
if (errno == ENOENT)
continue;
Expand Down

0 comments on commit b7041c0

Please sign in to comment.