[PATCH 1/3 resend] kernel32/tests: Test ReplaceFileW on open "exe"

Brock York twunknown at gmail.com
Mon Sep 3 05:15:17 CDT 2018


Replicate the scenario of an exe calling
ReplaceFileW on itself.
An exe calling ReplaceFileW on itself will fail
in Wine currently but succeed in Windows 7.
This seems to be the problem seen in bug 33845
where the WarFrame launcher will keep relaunching
itself because the launcher failed to replace
itself with the new version.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=33845
Signed-off-by: Brock York <twunknown at gmail.com>
---
 dlls/kernel32/tests/file.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c
index 1c4157279b..2e2c55bcc9 100644
--- a/dlls/kernel32/tests/file.c
+++ b/dlls/kernel32/tests/file.c
@@ -3677,6 +3677,30 @@ static void test_ReplaceFileA(void)
     ok(ret || GetLastError() == ERROR_ACCESS_DENIED,
        "SetFileAttributesA: error setting to normal %d\n", GetLastError());
 
+    /* re-create replacement file for pass w/ replaced opened with
+     * the same permissions as an exe (Replicating an exe trying to
+     * replace itself)
+     */
+    ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
+    ok(ret != 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    /* make sure that the replacement file still exists */
+    hReplacementFile = CreateFileA(replacement, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+    ok(hReplacementFile != INVALID_HANDLE_VALUE ||
+       broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* win2k */
+       "unexpected error, replacement file should still exist %d\n", GetLastError());
+    CloseHandle(hReplacementFile);
+
+    /* make sure that the replaced file is opened like an exe*/
+    hReplacedFile = CreateFileA(replaced, GENERIC_READ | SYNCHRONIZE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, 0);
+    ok(hReplacedFile != INVALID_HANDLE_VALUE,
+       "unexpected error, replaced file should be able to be opened %d\n", GetLastError());
+    /*Calling ReplaceFileA on an exe should succeed*/
+    ret = pReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
+    todo_wine ok(ret, "ReplaceFileA: unexpected error %d\n", GetLastError());
+    CloseHandle(hReplacedFile);
+
     /* replacement file still exists, make pass w/o "replaced" */
     ret = DeleteFileA(replaced);
     ok(ret || GetLastError() == ERROR_ACCESS_DENIED,
-- 
2.18.0




More information about the wine-devel mailing list