Skip to content

Commit

Permalink
[1.8>1.9] [MERGE #4633 @MikeHolman] add some asserts during jit hands…
Browse files Browse the repository at this point in the history
…hake

Merge pull request #4633 from MikeHolman:addasserts

Well behaved programs should never hit these paths, so add early asserts to catch bugs early in testing

OS: 15490382
  • Loading branch information
MikeHolman committed Feb 2, 2018
2 parents dc9c863 + c4d03a6 commit 1dd69bc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/JITServer/JITServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,28 @@ HRESULT CheckModuleAddress(HANDLE process, LPCVOID remoteImageBase, LPCVOID loca
SIZE_T resultBytes = VirtualQueryEx(process, (LPCVOID)remoteImageBase, &remoteImageInfo, sizeof(remoteImageInfo));
if (resultBytes != sizeof(remoteImageInfo))
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
if (remoteImageInfo.BaseAddress != (PVOID)remoteImageBase)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
if (remoteImageInfo.Type != MEM_IMAGE)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
if (remoteImageInfo.State != MEM_COMMIT)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}

if (remoteImageInfo.RegionSize < sizeof(remoteImageHeader))
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}

Expand All @@ -152,6 +157,7 @@ HRESULT CheckModuleAddress(HANDLE process, LPCVOID remoteImageBase, LPCVOID loca
}
if (resultBytes < sizeof(remoteImageHeader))
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
PIMAGE_DOS_HEADER localDosHeader = (PIMAGE_DOS_HEADER)localImageBase;
Expand All @@ -164,23 +170,28 @@ HRESULT CheckModuleAddress(HANDLE process, LPCVOID remoteImageBase, LPCVOID loca
uintptr_t remoteMaxRead = (uintptr_t)remoteNtHeader + sizeof(IMAGE_NT_HEADERS);
if (remoteMaxRead >= remoteHeaderMax || remoteMaxRead < (uintptr_t)remoteImageHeader)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}

if (localNtHeader->FileHeader.NumberOfSections != remoteNtHeader->FileHeader.NumberOfSections)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
if (localNtHeader->FileHeader.NumberOfSymbols != remoteNtHeader->FileHeader.NumberOfSymbols)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
if (localNtHeader->OptionalHeader.CheckSum != remoteNtHeader->OptionalHeader.CheckSum)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
if (localNtHeader->OptionalHeader.SizeOfImage != remoteNtHeader->OptionalHeader.SizeOfImage)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}

Expand All @@ -207,12 +218,14 @@ ServerConnectProcess(
HANDLE targetHandle;
if (!DuplicateHandle(GetCurrentProcess(), processHandle, GetCurrentProcess(), &targetHandle, 0, false, DUPLICATE_SAME_ACCESS))
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
#else
HANDLE targetHandle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_QUERY_LIMITED_INFORMATION, false, clientPid);
if (!targetHandle)
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}
#endif
Expand Down Expand Up @@ -902,6 +915,7 @@ ProcessContextManager::RegisterNewProcess(DWORD pid, HANDLE processHandle, intpt
// We cannot register multiple ProcessContexts for a single process
if (ProcessContexts.ContainsKey(pid))
{
Assert(UNREACHED);
return E_ACCESSDENIED;
}

Expand Down

0 comments on commit 1dd69bc

Please sign in to comment.