Dmitry Timoshkov : kernel32: Add more memory access checks.
Alexandre Julliard
julliard at winehq.org
Thu Apr 19 13:27:53 CDT 2012
Module: wine
Branch: master
Commit: d4d39736ceab567ecc7e9bdb077efad46ce3e5c4
URL: http://source.winehq.org/git/wine.git/?a=commit;h=d4d39736ceab567ecc7e9bdb077efad46ce3e5c4
Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date: Tue Apr 17 17:14:46 2012 +0900
kernel32: Add more memory access checks.
---
dlls/kernel32/tests/virtual.c | 96 ++++++++++++++++++++++++++++++++++++++---
1 files changed, 89 insertions(+), 7 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index b537ce0..73a5206 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -792,8 +792,25 @@ static void test_MapViewOfFile(void)
SetLastError(0xdeadbeef);
map2 = OpenFileMappingA(FILE_MAP_READ, FALSE, name);
ok( map2 != 0, "OpenFileMappingA failed with error %d\n", GetLastError() );
- CloseHandle(map2);
- CloseHandle(mapping);
+ SetLastError(0xdeadbeef);
+ ret = CloseHandle(map2);
+ ok(ret, "CloseHandle error %d\n", GetLastError());
+ SetLastError(0xdeadbeef);
+ ret = CloseHandle(mapping);
+ ok(ret, "CloseHandle error %d\n", GetLastError());
+
+ ret = IsBadReadPtr(ptr, MAPPING_SIZE);
+ ok( !ret, "memory is not accessible\n" );
+
+ ret = VirtualQuery(ptr, &info, sizeof(info));
+ ok(ret, "VirtualQuery error %d\n", GetLastError());
+ ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
+ ok(info.RegionSize == MAPPING_SIZE, "got %#lx != expected %#x\n", info.RegionSize, MAPPING_SIZE);
+ ok(info.Protect == PAGE_READWRITE, "got %#x != expected PAGE_READWRITE\n", info.Protect);
+ ok(info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr);
+ ok(info.AllocationProtect == PAGE_READWRITE, "%#x != PAGE_READWRITE\n", info.AllocationProtect);
+ ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
+ ok(info.Type == MEM_MAPPED, "%#x != MEM_MAPPED\n", info.Type);
SetLastError(0xdeadbeef);
map2 = OpenFileMappingA(FILE_MAP_READ, FALSE, name);
@@ -801,22 +818,46 @@ static void test_MapViewOfFile(void)
ok( map2 == 0, "OpenFileMappingA succeeded\n" );
todo_wine
ok( GetLastError() == ERROR_FILE_NOT_FOUND, "OpenFileMappingA set error %d\n", GetLastError() );
- CloseHandle(map2);
+ if (map2) CloseHandle(map2); /* FIXME: remove once Wine is fixed */
SetLastError(0xdeadbeef);
mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, MAPPING_SIZE, name);
ok( mapping != 0, "CreateFileMappingA failed\n" );
todo_wine
ok( GetLastError() == ERROR_SUCCESS, "CreateFileMappingA set error %d\n", GetLastError() );
- CloseHandle(mapping);
+ SetLastError(0xdeadbeef);
+ ret = CloseHandle(mapping);
+ ok(ret, "CloseHandle error %d\n", GetLastError());
ret = IsBadReadPtr(ptr, MAPPING_SIZE);
ok( !ret, "memory is not accessible\n" );
+
+ ret = VirtualQuery(ptr, &info, sizeof(info));
+ ok(ret, "VirtualQuery error %d\n", GetLastError());
+ ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
+ ok(info.RegionSize == MAPPING_SIZE, "got %#lx != expected %#x\n", info.RegionSize, MAPPING_SIZE);
+ ok(info.Protect == PAGE_READWRITE, "got %#x != expected PAGE_READWRITE\n", info.Protect);
+ ok(info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr);
+ ok(info.AllocationProtect == PAGE_READWRITE, "%#x != PAGE_READWRITE\n", info.AllocationProtect);
+ ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
+ ok(info.Type == MEM_MAPPED, "%#x != MEM_MAPPED\n", info.Type);
+
SetLastError(0xdeadbeef);
ret = UnmapViewOfFile(ptr);
ok( ret, "UnmapViewOfFile failed with error %d\n", GetLastError() );
+
ret = IsBadReadPtr(ptr, MAPPING_SIZE);
ok( ret, "memory is accessible\n" );
+ ret = VirtualQuery(ptr, &info, sizeof(info));
+ ok(ret, "VirtualQuery error %d\n", GetLastError());
+ ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
+ ok(info.RegionSize != MAPPING_SIZE, "got size %#lx\n", info.RegionSize);
+ ok(info.Protect == PAGE_NOACCESS, "got %#x != expected PAGE_NOACCESS\n", info.Protect);
+ ok(info.AllocationBase == NULL, "%p != NULL\n", info.AllocationBase);
+ ok(info.AllocationProtect == 0, "%#x != 0\n", info.AllocationProtect);
+ ok(info.State == MEM_FREE, "%#x != MEM_FREE\n", info.State);
+ ok(info.Type == 0, "%#x != 0\n", info.Type);
+
SetLastError(0xdeadbeef);
file = CreateFileA(testfile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
ok( file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
@@ -832,8 +873,25 @@ static void test_MapViewOfFile(void)
SetLastError(0xdeadbeef);
map2 = OpenFileMappingA(FILE_MAP_READ, FALSE, name);
ok( map2 != 0, "OpenFileMappingA failed with error %d\n", GetLastError() );
- CloseHandle(map2);
- CloseHandle(mapping);
+ SetLastError(0xdeadbeef);
+ ret = CloseHandle(map2);
+ ok(ret, "CloseHandle error %d\n", GetLastError());
+ SetLastError(0xdeadbeef);
+ ret = CloseHandle(mapping);
+ ok(ret, "CloseHandle error %d\n", GetLastError());
+
+ ret = IsBadReadPtr(ptr, MAPPING_SIZE);
+ ok( !ret, "memory is not accessible\n" );
+
+ ret = VirtualQuery(ptr, &info, sizeof(info));
+ ok(ret, "VirtualQuery error %d\n", GetLastError());
+ ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
+ ok(info.RegionSize == MAPPING_SIZE, "got %#lx != expected %#x\n", info.RegionSize, MAPPING_SIZE);
+ ok(info.Protect == PAGE_READWRITE, "got %#x != expected PAGE_READWRITE\n", info.Protect);
+ ok(info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr);
+ ok(info.AllocationProtect == PAGE_READWRITE, "%#x != PAGE_READWRITE\n", info.AllocationProtect);
+ ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
+ ok(info.Type == MEM_MAPPED, "%#x != MEM_MAPPED\n", info.Type);
SetLastError(0xdeadbeef);
map2 = OpenFileMappingA(FILE_MAP_READ, FALSE, name);
@@ -847,16 +905,40 @@ static void test_MapViewOfFile(void)
ok( mapping != 0, "CreateFileMappingA failed\n" );
todo_wine
ok( GetLastError() == ERROR_SUCCESS, "CreateFileMappingA set error %d\n", GetLastError() );
- CloseHandle(mapping);
+ SetLastError(0xdeadbeef);
+ ret = CloseHandle(mapping);
+ ok(ret, "CloseHandle error %d\n", GetLastError());
ret = IsBadReadPtr(ptr, MAPPING_SIZE);
ok( !ret, "memory is not accessible\n" );
+
+ ret = VirtualQuery(ptr, &info, sizeof(info));
+ ok(ret, "VirtualQuery error %d\n", GetLastError());
+ ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
+ ok(info.RegionSize == MAPPING_SIZE, "got %#lx != expected %#x\n", info.RegionSize, MAPPING_SIZE);
+ ok(info.Protect == PAGE_READWRITE, "got %#x != expected PAGE_READWRITE\n", info.Protect);
+ ok(info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr);
+ ok(info.AllocationProtect == PAGE_READWRITE, "%#x != PAGE_READWRITE\n", info.AllocationProtect);
+ ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
+ ok(info.Type == MEM_MAPPED, "%#x != MEM_MAPPED\n", info.Type);
+
SetLastError(0xdeadbeef);
ret = UnmapViewOfFile(ptr);
ok( ret, "UnmapViewOfFile failed with error %d\n", GetLastError() );
+
ret = IsBadReadPtr(ptr, MAPPING_SIZE);
ok( ret, "memory is accessible\n" );
+ ret = VirtualQuery(ptr, &info, sizeof(info));
+ ok(ret, "VirtualQuery error %d\n", GetLastError());
+ ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
+ ok(info.RegionSize != MAPPING_SIZE, "got size %#lx\n", info.RegionSize);
+ ok(info.Protect == PAGE_NOACCESS, "got %#x != expected PAGE_NOACCESS\n", info.Protect);
+ ok(info.AllocationBase == NULL, "%p != NULL\n", info.AllocationBase);
+ ok(info.AllocationProtect == 0, "%#x != 0\n", info.AllocationProtect);
+ ok(info.State == MEM_FREE, "%#x != MEM_FREE\n", info.State);
+ ok(info.Type == 0, "%#x != 0\n", info.Type);
+
CloseHandle(file);
DeleteFileA(testfile);
}
More information about the wine-cvs
mailing list