From b7cd53255606e8cd0030319df6b366afd86979bd Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 15 Oct 2005 17:28:08 +0000 Subject: * sysdeps/unix/fdopendir.c (fdopendir): Make sure descriptor allows reading. --- sysdeps/unix/fdopendir.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sysdeps') diff --git a/sysdeps/unix/fdopendir.c b/sysdeps/unix/fdopendir.c index ef6c97c..23d08fd 100644 --- a/sysdeps/unix/fdopendir.c +++ b/sysdeps/unix/fdopendir.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -35,6 +36,15 @@ fdopendir (int fd) __set_errno (ENOTDIR); return NULL; } + /* Make sure the descriptor allows for reading. */ + int flags = __fcntl (fd, F_GETFL); + if (__builtin_expect (flags == -1, 0)) + return NULL; + if (__builtin_expect ((flags & O_ACCMODE) == O_WRONLY, 0)) + { + __set_errno (EINVAL); + return NULL; + } return __alloc_dir (fd, false, &statbuf); } -- cgit v1.1