Module: wine Branch: master Commit: 27b74d8e3727b37ce0bc3b6f8cd04e1501485d4f URL: https://gitlab.winehq.org/wine/wine/-/commit/27b74d8e3727b37ce0bc3b6f8cd04e1...
Author: Paul Gofman pgofman@codeweavers.com Date: Thu Jun 20 14:31:07 2024 -0600
ntdll: Limit vprot scan range to the needed interval in get_working_set_ex().
---
dlls/ntdll/unix/virtual.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 1e5d9311b62..af3b40f949f 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -2140,7 +2140,7 @@ done: * Get the size of the committed range with equal masked vprot bytes starting at base. * Also return the protections for the first page. */ -static SIZE_T get_committed_size( struct file_view *view, void *base, BYTE *vprot, BYTE vprot_mask ) +static SIZE_T get_committed_size( struct file_view *view, void *base, size_t max_size, BYTE *vprot, BYTE vprot_mask ) { SIZE_T offset, size;
@@ -2159,7 +2159,7 @@ static SIZE_T get_committed_size( struct file_view *view, void *base, BYTE *vpro req->offset = offset; if (!wine_server_call( req )) { - size = reply->size; + size = min( reply->size, max_size ); if (reply->committed) { *vprot |= VPROT_COMMITTED; @@ -2171,7 +2171,7 @@ static SIZE_T get_committed_size( struct file_view *view, void *base, BYTE *vpro
if (!size || !(vprot_mask & ~VPROT_COMMITTED)) return size; } - else size = view->size - offset; + else size = min( view->size - offset, max_size );
return get_vprot_range_size( base, size, vprot_mask, vprot ); } @@ -4921,7 +4921,7 @@ NTSTATUS WINAPI NtProtectVirtualMemory( HANDLE process, PVOID *addr_ptr, SIZE_T if ((view = find_view( base, size ))) { /* Make sure all the pages are committed */ - if (get_committed_size( view, base, &vprot, VPROT_COMMITTED ) >= size && (vprot & VPROT_COMMITTED)) + if (get_committed_size( view, base, ~(size_t)0, &vprot, VPROT_COMMITTED ) >= size && (vprot & VPROT_COMMITTED)) { old = get_win32_prot( vprot, view->protect ); status = set_protection( view, base, size, new_prot ); @@ -5049,7 +5049,7 @@ static unsigned int fill_basic_memory_info( const void *addr, MEMORY_BASIC_INFOR BYTE vprot;
info->AllocationBase = alloc_base; - info->RegionSize = get_committed_size( view, base, &vprot, ~VPROT_WRITEWATCH ); + info->RegionSize = get_committed_size( view, base, ~(size_t)0, &vprot, ~VPROT_WRITEWATCH ); info->State = (vprot & VPROT_COMMITTED) ? MEM_COMMIT : MEM_RESERVE; info->Protect = (vprot & VPROT_COMMITTED) ? get_win32_prot( vprot, view->protect ) : 0; info->AllocationProtect = get_win32_prot( view->protect, view->protect ); @@ -5304,7 +5304,7 @@ static NTSTATUS get_working_set_ex( HANDLE process, LPCVOID addr, while (start != (char *)view->base + view->size && r != ref + count && r->addr < (char *)view->base + view->size) { - size = get_committed_size( view, start, &vprot, ~VPROT_WRITEWATCH ); + size = get_committed_size( view, start, end - start, &vprot, ~VPROT_WRITEWATCH ); while (r != ref + count && r->addr < start + size) { if (vprot & VPROT_COMMITTED) fill_working_set_info( &data, view, vprot, &info[r->orig_index] );