* sysdeps/unix/fdopendir.c (fdopendir): Make sure descriptor
authorUlrich Drepper <drepper@redhat.com>
Sat, 15 Oct 2005 17:28:08 +0000 (17:28 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 15 Oct 2005 17:28:08 +0000 (17:28 +0000)
allows reading.

ChangeLog
sysdeps/unix/fdopendir.c

index 1ff6ad9..ee604fb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2005-10-15  Ulrich Drepper  <drepper@redhat.com>
 
+       * sysdeps/unix/fdopendir.c (fdopendir): Make sure descriptor
+       allows reading.
+
        * wcsmbs/tst-mbrtowc2.c: Use de_DE.UTF-8 instead of en_US.UTF-8.
        * wcsmbs/Makefile: Define tst-mbrtowc2-ENV.
 
index ef6c97c..23d08fd 100644 (file)
@@ -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);
 }