wine-staging/patches/ntdll-Placeholders/0008-ntdll-Handle-NULL-process-handle-in-MapViewOfFile3.patch

59 lines
2.1 KiB
Diff
Raw Normal View History

2022-11-12 16:23:09 -08:00
From 72dcf52735e6306fa67f25f49fd78da24d7d89cb Mon Sep 17 00:00:00 2001
From: Paul Gofman <pgofman@codeweavers.com>
Date: Thu, 10 Nov 2022 18:40:18 -0600
Subject: [PATCH] ntdll: Handle NULL process handle in MapViewOfFile3().
Based on a patch by Nikolay Sivov.
---
dlls/kernelbase/memory.c | 2 ++
dlls/ntdll/tests/virtual.c | 13 +++++++++++++
2 files changed, 15 insertions(+)
diff --git a/dlls/kernelbase/memory.c b/dlls/kernelbase/memory.c
index c01fe817972..ee12f6abb91 100644
--- a/dlls/kernelbase/memory.c
+++ b/dlls/kernelbase/memory.c
@@ -255,6 +255,8 @@ LPVOID WINAPI DECLSPEC_HOTPATCH MapViewOfFile3( HANDLE handle, HANDLE process, P
LARGE_INTEGER off;
void *addr;
+ if (!process) process = GetCurrentProcess();
+
addr = baseaddr;
off.QuadPart = offset;
if (!set_ntstatus( NtMapViewOfSectionEx( handle, process, &addr, &off, &size, alloc_type, protection,
diff --git a/dlls/ntdll/tests/virtual.c b/dlls/ntdll/tests/virtual.c
index 0dccb35bd27..486efabaf70 100644
--- a/dlls/ntdll/tests/virtual.c
+++ b/dlls/ntdll/tests/virtual.c
@@ -1060,6 +1060,13 @@ static void test_NtMapViewOfSection(void)
process = create_target_process("sleep");
ok(process != NULL, "Can't start process\n");
+ ptr = NULL;
+ size = 0;
+ offset.QuadPart = 0;
+ status = NtMapViewOfSection(mapping, NULL, &ptr, 0, 0, &offset, &size, 1, 0, PAGE_READWRITE);
+ ok(status == STATUS_INVALID_HANDLE, "NtMapViewOfSection returned %08lx\n", status);
+ ok(!((ULONG_PTR)ptr & 0xffff), "returned memory %p is not aligned to 64k\n", ptr);
+
ptr = NULL;
size = 0;
offset.QuadPart = 0;
@@ -1303,6 +1310,12 @@ static void test_NtMapViewOfSectionEx(void)
process = create_target_process("sleep");
ok(process != NULL, "Can't start process\n");
+ ptr = NULL;
+ size = 0;
+ offset.QuadPart = 0;
+ status = pNtMapViewOfSectionEx(mapping, NULL, &ptr, &offset, &size, 0, PAGE_READWRITE, NULL, 0);
+ ok(status == STATUS_INVALID_HANDLE, "Unexpected status %08lx\n", status);
+
ptr = NULL;
size = 0;
offset.QuadPart = 0;
--
2.38.1