wine-staging/patches/ntdll-avoid-fstatat/0001-ntdll-Avoid-fstatat.patch

78 lines
2.9 KiB
Diff
Raw Normal View History

From 48d00ccab7205412a743438ae16fb209de9ff523 Mon Sep 17 00:00:00 2001
2020-03-28 11:22:08 -07:00
From: Zebediah Figura <z.figura12@gmail.com>
Date: Sat, 28 Mar 2020 13:17:25 -0500
Subject: [PATCH] ntdll: Avoid fstatat().
---
dlls/ntdll/directory.c | 3 +--
dlls/ntdll/file.c | 20 ++++++++++++++++++--
dlls/ntdll/ntdll_misc.h | 1 +
3 files changed, 20 insertions(+), 4 deletions(-)
2020-03-28 11:22:08 -07:00
diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c
index d18df38f626..eb33c7f541a 100644
--- a/dlls/ntdll/directory.c
+++ b/dlls/ntdll/directory.c
@@ -217,14 +217,13 @@ static const BOOL is_case_sensitive = FALSE;
static struct file_identity windir;
-static RTL_CRITICAL_SECTION dir_section;
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &dir_section,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": dir_section") }
};
-static RTL_CRITICAL_SECTION dir_section = { &critsect_debug, -1, 0, 0, 0, 0 };
+RTL_CRITICAL_SECTION dir_section = { &critsect_debug, -1, 0, 0, 0, 0 };
/* check if a given Unicode char is OK in a DOS short name */
2020-03-28 11:22:08 -07:00
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 9997a5e1cda..5d02f2fb181 100644
2020-03-28 11:22:08 -07:00
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -138,8 +138,24 @@ static inline ULONG get_file_attributes( const struct stat *st )
2020-03-28 11:22:08 -07:00
static BOOL fd_is_mount_point( int fd, const struct stat *st )
{
struct stat parent;
- return S_ISDIR( st->st_mode ) && !fstatat( fd, "..", &parent, 0 )
- && (parent.st_dev != st->st_dev || parent.st_ino == st->st_ino);
+ BOOL ret = FALSE;
+ int cwd;
+
+ if (!S_ISDIR( st->st_mode )) return FALSE;
+ RtlEnterCriticalSection( &dir_section );
+ if ((cwd = open(".", O_RDONLY) == -1))
+ {
+ RtlLeaveCriticalSection( &dir_section );
+ return FALSE;
+ }
2020-03-28 11:22:08 -07:00
+ if (!fchdir( fd ))
+ {
+ ret = !stat( "..", &parent ) && (parent.st_dev != st->st_dev || parent.st_ino == st->st_ino);
+ if (fchdir( cwd ) == -1) chdir( "/" );
+ }
+ close( cwd );
+ RtlLeaveCriticalSection( &dir_section );
2020-03-28 11:22:08 -07:00
+ return ret;
}
/* get the stat info and file attributes for a file (by file descriptor) */
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 76e8ec284e8..b32de1d60e5 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -190,6 +190,7 @@ extern unsigned int DIR_get_drives_info( struct drive_info info[MAX_DOS_DRIVES]
extern NTSTATUS file_id_to_unix_file_name( const OBJECT_ATTRIBUTES *attr, ANSI_STRING *unix_name_ret ) DECLSPEC_HIDDEN;
extern NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, ANSI_STRING *unix_name_ret,
UINT disposition ) DECLSPEC_HIDDEN;
+extern RTL_CRITICAL_SECTION dir_section DECLSPEC_HIDDEN;
/* virtual memory */
extern NTSTATUS virtual_alloc( PVOID *ret, unsigned short zero_bits_64, SIZE_T *size_ptr,
2020-03-28 11:22:08 -07:00
--
2.26.2
2020-03-28 11:22:08 -07:00