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

78 lines
2.9 KiB
Diff

From 06a8dec23dc20dae5ffe9288b7b85301b8118c0f Mon Sep 17 00:00:00 2001
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(-)
diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c
index 993a661015..a37b287a5a 100644
--- a/dlls/ntdll/directory.c
+++ b/dlls/ntdll/directory.c
@@ -219,14 +219,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 */
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index bd27d5a434..5173c203a2 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -139,8 +139,24 @@ static inline ULONG get_file_attributes( const struct stat *st )
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;
+ }
+ 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 );
+ 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 20feabf56b..2d98e5eab6 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -169,6 +169,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_aligned( PVOID *ret, unsigned short zero_bits_64, SIZE_T *size_ptr,
--
2.25.2