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

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


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

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

Also avoid fstat()+close() on non-directoy files.
(cherry picked from commit f9812a51e64e0777fa847fdf51f00fb500d2e1ca)

Conflicts:
	modules/access/directory.c

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

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

diff --git a/modules/access/directory.c b/modules/access/directory.c
index f958e12..4fcc872 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -38,7 +38,7 @@
 #ifdef HAVE_SYS_STAT_H
 #   include <sys/stat.h>
 #endif
-
+#include <errno.h>
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #   include <fcntl.h>
@@ -309,22 +309,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