[PATCH v2 4/4] kernel32: ReplaceFileW should fail with ERROR_ACCESS_DENIED on read only files

Brock York twunknown at gmail.com
Thu Aug 30 06:01:17 CDT 2018


ReplaceFileW should fail with ERROR_ACCESS_DENIED when either the replaced
or replacement file is set to read only using SetFileAttributes.
This solves the issue of ReplaceFileW tests failing with another patch
in this series because replacement was occuring on a file that is set
to read only.
Testing for the return values of ReplaceFileW was performed on a
Windows XP SP3 and Windows 10 vm.

Signed-off-by: Brock York <twunknown at gmail.com>
---
 dlls/kernel32/file.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c
index 3fdac41c50..1858866cf3 100644
--- a/dlls/kernel32/file.c
+++ b/dlls/kernel32/file.c
@@ -1738,6 +1738,7 @@ BOOL WINAPI ReplaceFileW(LPCWSTR lpReplacedFileName, LPCWSTR lpReplacementFileNa
     NTSTATUS status;
     IO_STATUS_BLOCK io;
     OBJECT_ATTRIBUTES attr;
+    DWORD fattribs;
 
     TRACE("%s %s %s 0x%08x %p %p\n", debugstr_w(lpReplacedFileName),
           debugstr_w(lpReplacementFileName), debugstr_w(lpBackupFileName),
@@ -1788,6 +1789,14 @@ BOOL WINAPI ReplaceFileW(LPCWSTR lpReplacedFileName, LPCWSTR lpReplacementFileNa
         goto fail;
     }
 
+    /* Replacement should fail if replaced is READ_ONLY */
+    fattribs = GetFileAttributesW(lpReplacedFileName);
+    if (fattribs & FILE_ATTRIBUTE_READONLY)
+    {
+        error = ERROR_ACCESS_DENIED;
+        goto fail;
+    }
+
     /*
      * Open the replacement file for reading, writing, and deleting
      * (writing and deleting are needed when finished)
@@ -1811,6 +1820,14 @@ BOOL WINAPI ReplaceFileW(LPCWSTR lpReplacedFileName, LPCWSTR lpReplacementFileNa
         goto fail;
     }
 
+    /* Replacement should fail if replacement is READ_ONLY */
+    fattribs = GetFileAttributesW(lpReplacementFileName);
+    if (fattribs & FILE_ATTRIBUTE_READONLY)
+    {
+        error = ERROR_ACCESS_DENIED;
+        goto fail;
+    }
+
     /* If the user wants a backup then that needs to be performed first */
     if (lpBackupFileName)
     {
-- 
2.18.0




More information about the wine-devel mailing list