From: Rich Felker Date: Tue, 7 Oct 2014 03:13:01 +0000 (-0400) Subject: ignore access mode bits of flags in mkostemps and functions that use it X-Git-Tag: v1.1.5~11 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6f1c1fe90c5b23ddf1ee8cce0ee7d77d392301a7;p=oweals%2Fmusl.git ignore access mode bits of flags in mkostemps and functions that use it per the text accepted for inclusion in POSIX, behavior is unspecified when any of the access mode bits are set. since it's impossible to consistently report this usage error (O_RDONLY could not be detected since its value happens to be zero), the most consistent way to handle them is just to ignore them. previously, if a caller erroneously passed O_WRONLY, the resulting access mode would be O_WRONLY|O_RDWR, which has the value 3, and this resulted in a file descriptor which rejects both read and write attempts when it is subsequently used. --- diff --git a/src/temp/mkostemps.c b/src/temp/mkostemps.c index 7f8492a1..512b5f18 100644 --- a/src/temp/mkostemps.c +++ b/src/temp/mkostemps.c @@ -15,6 +15,7 @@ int __mkostemps(char *template, int len, int flags) return -1; } + flags -= flags & O_ACCMODE; int fd, retries = 100; do { __randname(template+l-len-6);