Alexandre Julliard : ntdll: Ignore some system directories in NtQueryDirectoryFile to avoid recursion troubles .

Alexandre Julliard julliard at winehq.org
Tue Oct 28 10:02:31 CDT 2008


Module: wine
Branch: master
Commit: f0fed2831a6c6b305681b857729fce348691eaa5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f0fed2831a6c6b305681b857729fce348691eaa5

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Oct 28 13:55:24 2008 +0100

ntdll: Ignore some system directories in NtQueryDirectoryFile to avoid recursion troubles.

---

 dlls/ntdll/directory.c |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c
index dee0ce6..60f85ed 100644
--- a/dlls/ntdll/directory.c
+++ b/dlls/ntdll/directory.c
@@ -23,6 +23,7 @@
 #include "config.h"
 #include "wine/port.h"
 
+#include <assert.h>
 #include <sys/types.h>
 #ifdef HAVE_DIRENT_H
 # include <dirent.h>
@@ -136,6 +137,15 @@ static inline int getdents64( int fd, char *de, unsigned int size )
 
 #define MAX_DIR_ENTRY_LEN 255  /* max length of a directory entry in chars */
 
+#define MAX_IGNORED_FILES 4
+
+static struct
+{
+    dev_t dev;
+    ino_t ino;
+} ignored_files[MAX_IGNORED_FILES];
+static int ignored_files_count;
+
 static const unsigned int max_dir_info_size = FIELD_OFFSET( FILE_BOTH_DIR_INFORMATION, FileName[MAX_DIR_ENTRY_LEN] );
 
 static int show_dot_files = -1;
@@ -172,6 +182,28 @@ static inline int is_valid_mounted_device( const struct stat *st )
 #endif
 }
 
+static inline void ignore_file( const char *name )
+{
+    struct stat st;
+    assert( ignored_files_count < MAX_IGNORED_FILES );
+    if (!stat( name, &st ))
+    {
+        ignored_files[ignored_files_count].dev = st.st_dev;
+        ignored_files[ignored_files_count].ino = st.st_ino;
+        ignored_files_count++;
+    }
+}
+
+static inline BOOL is_ignored_file( const struct stat *st )
+{
+    unsigned int i;
+
+    for (i = 0; i < ignored_files_count; i++)
+        if (ignored_files[i].dev == st->st_dev && ignored_files[i].ino == st->st_ino)
+            return TRUE;
+    return FALSE;
+}
+
 /***********************************************************************
  *           get_default_com_device
  *
@@ -694,6 +726,14 @@ static void init_options(void)
         NtClose( hkey );
     }
     NtClose( root );
+
+    /* a couple of directories that we don't want to return in directory searches */
+    ignore_file( wine_get_config_dir() );
+    ignore_file( "/dev" );
+    ignore_file( "/proc" );
+#ifdef linux
+    ignore_file( "/sys" );
+#endif
 }
 
 
@@ -929,6 +969,11 @@ static FILE_BOTH_DIR_INFORMATION *append_entry( void *info_ptr, ULONG_PTR *pos,
         if (stat( long_name, &st ) == -1) return NULL;
         if (S_ISDIR( st.st_mode )) info->FileAttributes |= FILE_ATTRIBUTE_REPARSE_POINT;
     }
+    if (is_ignored_file( &st ))
+    {
+        TRACE( "ignoring file %s\n", long_name );
+        return NULL;
+    }
 
     info->NextEntryOffset = total_len;
     info->FileIndex = 0;  /* NTFS always has 0 here, so let's not bother with it */




More information about the wine-cvs mailing list