From 0f72df72b94bf1a80a46f30e5896f1e916bb3380 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 11 Mar 2016 15:43:42 +0100 Subject: [PATCH] kernel32: Don't set unconditionally SECTION_QUERY flag in OpenFileMapping. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard (cherry picked from commit e625e86ee126b923703ad3ca728acff09f1e8812) Signed-off-by: Michael Stefaniuc --- dlls/advapi32/tests/security.c | 32 ++++++++++++++++++++++++++++++-- dlls/kernel32/virtual.c | 1 - 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c index 4bc3c023509..4eb168acd9d 100644 --- a/dlls/advapi32/tests/security.c +++ b/dlls/advapi32/tests/security.c @@ -5336,17 +5336,23 @@ static void test_filemap_security(void) char temp_path[MAX_PATH]; char file_name[MAX_PATH]; DWORD ret, i, access; - HANDLE file, mapping, dup; + HANDLE file, mapping, dup, created_mapping; static const struct { int generic, mapped; + BOOL open_only; } map[] = { { 0, 0 }, { GENERIC_READ, STANDARD_RIGHTS_READ | SECTION_QUERY | SECTION_MAP_READ }, { GENERIC_WRITE, STANDARD_RIGHTS_WRITE | SECTION_MAP_WRITE }, { GENERIC_EXECUTE, STANDARD_RIGHTS_EXECUTE | SECTION_MAP_EXECUTE }, - { GENERIC_ALL, STANDARD_RIGHTS_REQUIRED | SECTION_ALL_ACCESS } + { GENERIC_ALL, STANDARD_RIGHTS_REQUIRED | SECTION_ALL_ACCESS }, + { SECTION_MAP_READ | SECTION_MAP_WRITE, SECTION_MAP_READ | SECTION_MAP_WRITE }, + { SECTION_MAP_WRITE, SECTION_MAP_WRITE }, + { SECTION_MAP_READ | SECTION_QUERY, SECTION_MAP_READ | SECTION_QUERY }, + { SECTION_QUERY, SECTION_MAP_READ, TRUE }, + { SECTION_QUERY | SECTION_MAP_READ, SECTION_QUERY | SECTION_MAP_READ } }; static const struct { @@ -5375,6 +5381,8 @@ static void test_filemap_security(void) for (i = 0; i < sizeof(prot_map)/sizeof(prot_map[0]); i++) { + if (map[i].open_only) continue; + SetLastError(0xdeadbeef); mapping = CreateFileMappingW(file, NULL, prot_map[i].prot, 0, 4096, NULL); if (prot_map[i].mapped) @@ -5421,6 +5429,8 @@ static void test_filemap_security(void) for (i = 0; i < sizeof(map)/sizeof(map[0]); i++) { + if (map[i].open_only) continue; + SetLastError( 0xdeadbeef ); ret = DuplicateHandle(GetCurrentProcess(), mapping, GetCurrentProcess(), &dup, map[i].generic, FALSE, 0); @@ -5435,6 +5445,24 @@ static void test_filemap_security(void) CloseHandle(mapping); CloseHandle(file); DeleteFileA(file_name); + + created_mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 0x1000, + "Wine Test Open Mapping"); + ok(created_mapping != NULL, "CreateFileMapping failed with error %u\n", GetLastError()); + + for (i = 0; i < sizeof(map)/sizeof(map[0]); i++) + { + if (!map[i].generic) continue; + + mapping = OpenFileMappingA(map[i].generic, FALSE, "Wine Test Open Mapping"); + ok(mapping != NULL, "OpenFileMapping failed with error %d\n", GetLastError()); + access = get_obj_access(mapping); + ok(access == map[i].mapped, "%d: unexpected access flags %#x, expected %#x\n", + i, access, map[i].mapped); + CloseHandle(mapping); + } + + CloseHandle(created_mapping); } static void test_thread_security(void) diff --git a/dlls/kernel32/virtual.c b/dlls/kernel32/virtual.c index cce707bb95c..32f2d65a921 100644 --- a/dlls/kernel32/virtual.c +++ b/dlls/kernel32/virtual.c @@ -472,7 +472,6 @@ HANDLE WINAPI OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name) RtlInitUnicodeString( &nameW, name ); if (access == FILE_MAP_COPY) access = SECTION_MAP_READ; - access |= SECTION_QUERY; if (GetVersion() & 0x80000000) { -- 2.11.4.GIT