From a3c80349e7d6aa6322ba05792d53942ade57df9d Mon Sep 17 00:00:00 2001 From: jilles Date: Mon, 21 Apr 2014 17:40:23 +0000 Subject: 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/freopen.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/libc/stdio/freopen.c') diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index dc5508d..0ff83bf 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -92,8 +92,9 @@ freopen(const char * __restrict file, const char * __restrict mode, errno = sverrno; return (NULL); } - if ((dflags & O_ACCMODE) != O_RDWR && (dflags & O_ACCMODE) != - (oflags & O_ACCMODE)) { + /* Work around incorrect O_ACCMODE. */ + if ((dflags & O_ACCMODE) != O_RDWR && + (dflags & (O_ACCMODE | O_EXEC)) != (oflags & O_ACCMODE)) { fclose(fp); FUNLOCKFILE(fp); errno = EINVAL; -- cgit v1.1