diff options
author | 2015-05-11 00:42:54 +0000 | |
---|---|---|
committer | 2015-05-11 00:42:54 +0000 | |
commit | dc519336cc6495b5a61e8b6564dc5dc717ce145a (patch) | |
tree | 7566cb6538c290b5609f5f24676148488439fbf2 /lib/libc/gen/shm_open.c | |
parent | Set POLLHUP even if no valid events were specified as per POSIX. (diff) | |
download | wireguard-openbsd-dc519336cc6495b5a61e8b6564dc5dc717ce145a.tar.xz wireguard-openbsd-dc519336cc6495b5a61e8b6564dc5dc717ce145a.zip |
When checking flags that will be passed to open(), test the O_ACCMODE portion
separately to avoid false negatives.
ok miod@ millert@
Diffstat (limited to 'lib/libc/gen/shm_open.c')
-rw-r--r-- | lib/libc/gen/shm_open.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/libc/gen/shm_open.c b/lib/libc/gen/shm_open.c index 4e15bfa6689..1ebe7c86257 100644 --- a/lib/libc/gen/shm_open.c +++ b/lib/libc/gen/shm_open.c @@ -1,4 +1,4 @@ -/* $OpenBSD: shm_open.c,v 1.4 2013/11/12 06:09:48 deraadt Exp $ */ +/* $OpenBSD: shm_open.c,v 1.5 2015/05/11 00:42:54 guenther Exp $ */ /* * Copyright (c) 2013 Ted Unangst <tedu@openbsd.org> * @@ -31,6 +31,9 @@ /* "/tmp/" + sha256 + ".shm" */ #define SHM_PATH_SIZE (5 + SHA256_DIGEST_STRING_LENGTH + 4) +/* O_CLOEXEC and O_NOFOLLOW are extensions to POSIX */ +#define OK_FLAGS (O_CREAT | O_EXCL | O_TRUNC | O_CLOEXEC | O_NOFOLLOW) + static void makeshmpath(const char *origpath, char *shmpath, size_t len) { @@ -47,8 +50,8 @@ shm_open(const char *path, int flags, mode_t mode) struct stat sb; int fd; - if (flags & ~(O_RDONLY | O_RDWR | - O_CREAT | O_EXCL | O_TRUNC | O_CLOEXEC | O_NOFOLLOW)) { + if (((flags & O_ACCMODE) != O_RDONLY && (flags & O_ACCMODE) != O_RDWR) + || (flags & ~(O_ACCMODE | OK_FLAGS))) { errno = EINVAL; return -1; } |