Commit 1a3777e2 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Reject VirtualAlloc blocks in NtUnmapViewOfSection.

parent 416cd484
......@@ -748,6 +748,24 @@ static void test_MapViewOfFile(void)
ret = UnmapViewOfFile(ptr);
ok(ret, "UnmapViewOfFile failed with error %d\n", GetLastError());
CloseHandle(mapping);
addr = VirtualAlloc(NULL, 0x10000, MEM_COMMIT, PAGE_READONLY );
ok( addr != NULL, "VirtualAlloc failed with error %u\n", GetLastError() );
SetLastError(0xdeadbeef);
ok( !UnmapViewOfFile(addr), "UnmapViewOfFile should fail on VirtualAlloc mem\n" );
ok( GetLastError() == ERROR_INVALID_ADDRESS,
"got %u, expected ERROR_INVALID_ADDRESS\n", GetLastError());
SetLastError(0xdeadbeef);
ok( !UnmapViewOfFile((char *)addr + 0x3000), "UnmapViewOfFile should fail on VirtualAlloc mem\n" );
ok( GetLastError() == ERROR_INVALID_ADDRESS,
"got %u, expected ERROR_INVALID_ADDRESS\n", GetLastError());
SetLastError(0xdeadbeef);
ok( !UnmapViewOfFile((void *)0xdeadbeef), "UnmapViewOfFile should fail on VirtualAlloc mem\n" );
ok( GetLastError() == ERROR_INVALID_ADDRESS,
"got %u, expected ERROR_INVALID_ADDRESS\n", GetLastError());
ok( VirtualFree(addr, 0, MEM_RELEASE), "VirtualFree failed\n" );
}
static DWORD (WINAPI *pNtMapViewOfSection)( HANDLE handle, HANDLE process, PVOID *addr_ptr,
......
......@@ -2533,7 +2533,7 @@ done:
NTSTATUS WINAPI NtUnmapViewOfSection( HANDLE process, PVOID addr )
{
FILE_VIEW *view;
NTSTATUS status = STATUS_INVALID_PARAMETER;
NTSTATUS status = STATUS_NOT_MAPPED_VIEW;
sigset_t sigset;
void *base = ROUND_ADDR( addr, page_mask );
......@@ -2552,7 +2552,7 @@ NTSTATUS WINAPI NtUnmapViewOfSection( HANDLE process, PVOID addr )
}
server_enter_uninterrupted_section( &csVirtual, &sigset );
if ((view = VIRTUAL_FindView( base, 0 )) && (base == view->base))
if ((view = VIRTUAL_FindView( base, 0 )) && (base == view->base) && !(view->protect & VPROT_VALLOC))
{
delete_view( view );
status = STATUS_SUCCESS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment