summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-04-21 17:40:23 +0000
committerjilles <jilles@FreeBSD.org>2014-04-21 17:40:23 +0000
commita3c80349e7d6aa6322ba05792d53942ade57df9d (patch)
tree64121b0b1142a6b56d9bed6961f9161daa1d30d3 /lib
parent08414b8dda2e9ba3198516394f5edec20853f9f5 (diff)
downloadFreeBSD-src-a3c80349e7d6aa6322ba05792d53942ade57df9d.zip
FreeBSD-src-a3c80349e7d6aa6322ba05792d53942ade57df9d.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/fdopen.c3
-rw-r--r--lib/libc/stdio/freopen.c5
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c
index 2e19b9f..b936998 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);
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;
OpenPOWER on IntegriCloud