mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2025-01-28 22:04:43 -08:00
ntdll-avoid-fstatat: Protect cwd manipulation with dir_section.
This commit is contained in:
parent
b14430433d
commit
af97ec8ce0
@ -1,17 +1,39 @@
|
||||
From 997cebb3b42bb30bdfaab21c6e8260d7088ac972 Mon Sep 17 00:00:00 2001
|
||||
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/file.c | 14 ++++++++++++--
|
||||
1 file changed, 12 insertions(+), 2 deletions(-)
|
||||
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..e64435252f 100644
|
||||
index bd27d5a434..5173c203a2 100644
|
||||
--- a/dlls/ntdll/file.c
|
||||
+++ b/dlls/ntdll/file.c
|
||||
@@ -139,8 +139,18 @@ static inline ULONG get_file_attributes( const struct stat *st )
|
||||
@@ -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;
|
||||
@ -21,17 +43,35 @@ index bd27d5a434..e64435252f 100644
|
||||
+ int cwd;
|
||||
+
|
||||
+ if (!S_ISDIR( st->st_mode )) return FALSE;
|
||||
+ if ((cwd = open(".", O_RDONLY) == -1)) 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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user