about summary refs log tree commit diff
path: root/sysdeps/unix/fdopendir.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-10-15 17:28:08 +0000
committerUlrich Drepper <drepper@redhat.com>2005-10-15 17:28:08 +0000
commitb7cd53255606e8cd0030319df6b366afd86979bd (patch)
treebb5062b1658dfc9185337d33c1f6425c8f2d1c62 /sysdeps/unix/fdopendir.c
parentebb58ba3c23dc0d24d1b09aafd289f208ce6e75b (diff)
downloadglibc-b7cd53255606e8cd0030319df6b366afd86979bd.tar.gz
glibc-b7cd53255606e8cd0030319df6b366afd86979bd.tar.xz
glibc-b7cd53255606e8cd0030319df6b366afd86979bd.zip
* sysdeps/unix/fdopendir.c (fdopendir): Make sure descriptor
	allows reading.
Diffstat (limited to 'sysdeps/unix/fdopendir.c')
-rw-r--r--sysdeps/unix/fdopendir.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/sysdeps/unix/fdopendir.c b/sysdeps/unix/fdopendir.c
index ef6c97c308..23d08fd7fd 100644
--- a/sysdeps/unix/fdopendir.c
+++ b/sysdeps/unix/fdopendir.c
@@ -18,6 +18,7 @@
 
 #include <dirent.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <sys/stat.h>
 
 #include <not-cancel.h>
@@ -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);
 }