diff options
| author | admin <s0las16.224@gmail.com> | 2026-11-22 18:00:33 +0000 |
|---|---|---|
| committer | admin <s0las16.224@gmail.com> | 2026-11-22 18:00:33 +0000 |
| commit | 585143544e76954905535335ab98e7ab2ea7c23c (patch) | |
| tree | dcb69cdfc24f0702ebb952af5bfee63ec2afb4b9 /runtime/src/pe_loader.cpp | |
| parent | 49475796c226c8511b9470bf97a4daf57b8af323 (diff) | |
Reject out-of-image entry points before loader initialization
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Diffstat (limited to 'runtime/src/pe_loader.cpp')
| -rw-r--r-- | runtime/src/pe_loader.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index bdb3df6f5..c19321684 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp | |||
| @@ -574,7 +574,6 @@ void Loader::initialise(Module& m) { | |||
| 574 | // Only a DLL gets DllMain. An EXE's entry point has a different signature and is the caller's to run. | 574 | // Only a DLL gets DllMain. An EXE's entry point has a different signature and is the caller's to run. |
| 575 | auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew); | 575 | auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew); |
| 576 | if ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) && m.entry_rva) { | 576 | if ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) && m.entry_rva) { |
| 577 | if (m.entry_rva >= m.size) throw std::runtime_error(m.name + ": the entry point is outside the image"); | ||
| 578 | auto entry = reinterpret_cast<BOOL(NTAPI*)(void*, DWORD, void*)>(m.base + m.entry_rva); | 577 | auto entry = reinterpret_cast<BOOL(NTAPI*)(void*, DWORD, void*)>(m.base + m.entry_rva); |
| 579 | const BOOL ok = entry(m.base, DLL_PROCESS_ATTACH, nullptr); | 578 | const BOOL ok = entry(m.base, DLL_PROCESS_ATTACH, nullptr); |
| 580 | if (startup_trace::enabled()) | 579 | if (startup_trace::enabled()) |
| @@ -619,6 +618,8 @@ Module& Loader::map_image(const std::filesystem::path& path) { | |||
| 619 | if (!oh.SizeOfImage || oh.SizeOfHeaders < headers_end || oh.SizeOfHeaders > oh.SizeOfImage || | 618 | if (!oh.SizeOfImage || oh.SizeOfHeaders < headers_end || oh.SizeOfHeaders > oh.SizeOfImage || |
| 620 | oh.SizeOfHeaders > file.size()) | 619 | oh.SizeOfHeaders > file.size()) |
| 621 | throw std::runtime_error(name + ": SizeOfHeaders and SizeOfImage don't fit the headers and file"); | 620 | throw std::runtime_error(name + ": SizeOfHeaders and SizeOfImage don't fit the headers and file"); |
| 621 | if (oh.AddressOfEntryPoint && oh.AddressOfEntryPoint >= oh.SizeOfImage) | ||
| 622 | throw std::runtime_error(name + ": the entry point is outside the image"); | ||
| 622 | 623 | ||
| 623 | auto* m = new Module; | 624 | auto* m = new Module; |
| 624 | m->name = name; | 625 | m->name = name; |