Fix process memory iteration in Windows.
PR wasn't correct. VirtualQueryEx doesn't update the last error code on success, so GetLastError can return arbitrary and unrelated error codes. This commit is a simplified variant of PR
@@ -153,7 +153,9 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block(
while (address < proc_info->si.lpMaximumApplicationAddress &&
VirtualQueryEx(proc_info->hProcess, address, &mbi, sizeof(mbi)) != 0)
{
- if (GetLastError() != ERROR_SUCCESS)
+ // mbi.RegionSize can overflow address while scanning a 64-bit process
+ // with a 32-bit YARA.
+ if ((uint8_t*) address + mbi.RegionSize <= address)
break;
if (mbi.State == MEM_COMMIT && ((mbi.Protect & PAGE_NOACCESS) == 0))
