ntdll: Tweak the file mapping permission checks some more, with tests.

This commit is contained in:
Alexandre Julliard 2009-05-19 21:36:05 +02:00
parent d4e1d88722
commit d5d0738fb9
4 changed files with 39 additions and 7 deletions

View File

@ -328,7 +328,7 @@ static void test_MapViewOfFile(void)
{ {
static const char testfile[] = "testfile.xxx"; static const char testfile[] = "testfile.xxx";
const char *name; const char *name;
HANDLE file, mapping; HANDLE file, mapping, map2;
void *ptr, *ptr2; void *ptr, *ptr2;
MEMORY_BASIC_INFORMATION info; MEMORY_BASIC_INFORMATION info;
BOOL ret; BOOL ret;
@ -365,6 +365,39 @@ static void test_MapViewOfFile(void)
ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 ); ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE error %u\n", GetLastError() ); ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE error %u\n", GetLastError() );
UnmapViewOfFile( ptr ); UnmapViewOfFile( ptr );
ret = DuplicateHandle( GetCurrentProcess(), mapping, GetCurrentProcess(), &map2,
FILE_MAP_READ|FILE_MAP_WRITE, FALSE, 0 );
ok( ret, "DuplicateHandle failed error %u\n", GetLastError());
ptr = MapViewOfFile( map2, FILE_MAP_WRITE, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE error %u\n", GetLastError() );
UnmapViewOfFile( ptr );
CloseHandle( map2 );
ret = DuplicateHandle( GetCurrentProcess(), mapping, GetCurrentProcess(), &map2,
FILE_MAP_READ, FALSE, 0 );
ok( ret, "DuplicateHandle failed error %u\n", GetLastError());
ptr = MapViewOfFile( map2, FILE_MAP_WRITE, 0, 0, 4096 );
if (!ptr)
{
ok( GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
CloseHandle( map2 );
ret = DuplicateHandle( GetCurrentProcess(), mapping, GetCurrentProcess(), &map2, 0, FALSE, 0 );
ok( ret, "DuplicateHandle failed error %u\n", GetLastError());
ptr = MapViewOfFile( map2, 0, 0, 0, 4096 );
ok( !ptr, "MapViewOfFile succeeded\n" );
ok( GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
CloseHandle( map2 );
ret = DuplicateHandle( GetCurrentProcess(), mapping, GetCurrentProcess(), &map2,
FILE_MAP_READ, FALSE, 0 );
ok( ret, "DuplicateHandle failed error %u\n", GetLastError());
ptr = MapViewOfFile( map2, 0, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile NO_ACCESS error %u\n", GetLastError() );
}
else win_skip( "no access checks on win9x\n" );
UnmapViewOfFile( ptr );
CloseHandle( map2 );
CloseHandle( mapping ); CloseHandle( mapping );
/* read-only mapping */ /* read-only mapping */

View File

@ -539,9 +539,8 @@ LPVOID WINAPI MapViewOfFileEx( HANDLE handle, DWORD access,
offset.u.HighPart = offset_high; offset.u.HighPart = offset_high;
if (access & FILE_MAP_WRITE) protect = PAGE_READWRITE; if (access & FILE_MAP_WRITE) protect = PAGE_READWRITE;
else if (access & FILE_MAP_READ) protect = PAGE_READONLY;
else if (access & FILE_MAP_COPY) protect = PAGE_WRITECOPY; else if (access & FILE_MAP_COPY) protect = PAGE_WRITECOPY;
else protect = PAGE_NOACCESS; else protect = PAGE_READONLY;
if (access & FILE_MAP_EXECUTE) protect <<= 4; if (access & FILE_MAP_EXECUTE) protect <<= 4;

View File

@ -2288,18 +2288,18 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
switch(protect) switch(protect)
{ {
case PAGE_NOACCESS: case PAGE_NOACCESS:
access = SECTION_QUERY; access = 0;
break; break;
case PAGE_READWRITE: case PAGE_READWRITE:
case PAGE_EXECUTE_READWRITE: case PAGE_EXECUTE_READWRITE:
access = SECTION_QUERY | SECTION_MAP_WRITE; access = SECTION_MAP_WRITE;
break; break;
case PAGE_READONLY: case PAGE_READONLY:
case PAGE_WRITECOPY: case PAGE_WRITECOPY:
case PAGE_EXECUTE: case PAGE_EXECUTE:
case PAGE_EXECUTE_READ: case PAGE_EXECUTE_READ:
case PAGE_EXECUTE_WRITECOPY: case PAGE_EXECUTE_WRITECOPY:
access = SECTION_QUERY | SECTION_MAP_READ; access = SECTION_MAP_READ;
break; break;
default: default:
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;

View File

@ -562,7 +562,7 @@ DECL_HANDLER(get_mapping_info)
struct fd *fd; struct fd *fd;
if ((mapping = (struct mapping *)get_handle_obj( current->process, req->handle, if ((mapping = (struct mapping *)get_handle_obj( current->process, req->handle,
req->access | SECTION_QUERY, &mapping_ops ))) req->access, &mapping_ops )))
{ {
reply->size = mapping->size; reply->size = mapping->size;
reply->protect = mapping->protect; reply->protect = mapping->protect;