From 65f700c61c7cb7cf82a5f23c5b327700a13fe6db Mon Sep 17 00:00:00 2001 From: ngie Date: Wed, 25 Nov 2015 08:19:01 +0000 Subject: MFC r264737: Discussed with: jilles r264737 (by jilles): libc/stdio: Fail fdopen() on an execute-only fd. An execute-only fd (opened with O_EXEC) allows neither read() nor write() and is therefore incompatible with all stdio modes. Therefore, the [EINVAL] error applies. Also adjust the similar check in freopen() with a NULL path, even though this checks an fd which is already from a FILE. --- lib/libc/stdio/fdopen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/libc/stdio/fdopen.c') diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index e5d167a..fbe37e8 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -70,7 +70,8 @@ fdopen(int fd, const char *mode) /* Make sure the mode the user wants is a subset of the actual mode. */ if ((fdflags = _fcntl(fd, F_GETFL, 0)) < 0) return (NULL); - tmp = fdflags & O_ACCMODE; + /* Work around incorrect O_ACCMODE. */ + tmp = fdflags & (O_ACCMODE | O_EXEC); if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) { errno = EINVAL; return (NULL); -- cgit v1.1