upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/pe_loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index 9c12733c6..3558cffb5 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -1829,6 +1829,11 @@ void Loader::initialize_tls(Module& m) {
1829 if (tls->AddressOfIndex) { 1829 if (tls->AddressOfIndex) {
1830 index_rva = rva_in(m, tls->AddressOfIndex, "the TLS index"); 1830 index_rva = rva_in(m, tls->AddressOfIndex, "the TLS index");
1831 require_range(m.name, index_rva, sizeof(uint32_t), m.size, "the TLS index"); 1831 require_range(m.name, index_rva, sizeof(uint32_t), m.size, "the TLS index");
1832 // The index is written below, and every later step reads the headers back from the mapping. An index at
1833 // RVA 0 would not be written at all (index_rva doubles as "no index").
1834 const auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew);
1835 if (index_rva < nt->OptionalHeader.SizeOfHeaders)
1836 throw std::runtime_error(m.name + ": the TLS index lands in the headers");
1832 } 1837 }
1833 1838
1834 if (!module_tls_slots()) throw std::runtime_error(m.name + ": this thread has no TLS array"); 1839 if (!module_tls_slots()) throw std::runtime_error(m.name + ": this thread has no TLS array");
@@ -2113,6 +2118,9 @@ void* Loader::resolve(Module& m, const std::string& dll, const std::string& name
2113 2118
2114void Loader::bind_imports(Module& m) { 2119void Loader::bind_imports(Module& m) {
2115 auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew); 2120 auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew);
2121 // Read before the first address is written: an entry in the headers would replace what the steps after this
2122 // one read back from the mapping (e_lfanew, the section table), so it is refused like a section there.
2123 const uint64_t headers_end = nt->OptionalHeader.SizeOfHeaders;
2116 2124
2117 // Thunk tables have no length field: they end at a zero entry, so each step is checked against the image. 2125 // Thunk tables have no length field: they end at a zero entry, so each step is checked against the image.
2118 auto bind_thunks = [&](const std::string& dll, uint64_t lookup_rva, uint64_t iat_rva) { 2126 auto bind_thunks = [&](const std::string& dll, uint64_t lookup_rva, uint64_t iat_rva) {
@@ -2129,6 +2137,8 @@ void Loader::bind_imports(Module& m) {
2129 uint32_t hint = static_cast<uint32_t>(lookup->u1.AddressOfData); 2137 uint32_t hint = static_cast<uint32_t>(lookup->u1.AddressOfData);
2130 name = read_string(m.name, m.base, m.size, hint + sizeof(uint16_t), "an import name"); 2138 name = read_string(m.name, m.base, m.size, hint + sizeof(uint16_t), "an import name");
2131 } 2139 }
2140 if (iat_rva < headers_end)
2141 throw std::runtime_error(m.name + ": an import address table lands in the headers");
2132 at<IMAGE_THUNK_DATA64>(m.base, static_cast<uint32_t>(iat_rva))->u1.Function = 2142 at<IMAGE_THUNK_DATA64>(m.base, static_cast<uint32_t>(iat_rva))->u1.Function =
2133 reinterpret_cast<uint64_t>(resolve(m, dll, name, ord, by_ord)); 2143 reinterpret_cast<uint64_t>(resolve(m, dll, name, ord, by_ord));
2134 } 2144 }