[vlc-commits] directory: do not get stuck on a FIFO (fix #6940)

Rémi Denis-Courmont git at videolan.org
Wed Jun 20 07:19:26 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jun 20 08:17:26 2012 +0300| [f9812a51e64e0777fa847fdf51f00fb500d2e1ca] | committer: Rémi Denis-Courmont

directory: do not get stuck on a FIFO (fix #6940)

Also avoid fstat()+close() on non-directoy files.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f9812a51e64e0777fa847fdf51f00fb500d2e1ca
---

 modules/access/directory.c |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/modules/access/directory.c b/modules/access/directory.c
index 10d2103..4ab97af 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -36,6 +36,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <errno.h>
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #   include <fcntl.h>
@@ -324,22 +325,18 @@ block_t *DirBlock (access_t *p_access)
     {
         DIR *handle;
 #ifdef HAVE_OPENAT
-        int fd = vlc_openat (dirfd (current->handle), entry, O_RDONLY);
+        int fd = vlc_openat (dirfd (current->handle), entry,
+                             O_RDONLY | O_DIRECTORY);
         if (fd == -1)
+        {
+            if (errno == ENOTDIR)
+                goto notdir;
             goto skip; /* File cannot be opened... forget it */
+        }
 
         struct stat st;
-        if (fstat (fd, &st))
-        {
-            close (fd);
-            goto skip; /* cannot stat?! */
-        }
-        if (!S_ISDIR (st.st_mode))
-        {
-            close (fd);
-            goto notdir;
-        }
-        if (p_sys->mode == MODE_NONE
+        if (fstat (fd, &st)
+         || p_sys->mode == MODE_NONE
          || has_inode_loop (current, st.st_dev, st.st_ino)
          || (handle = fdopendir (fd)) == NULL)
         {



More information about the vlc-commits mailing list