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/test/loader_test.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/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index 194174b00..9ff3d08c2 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -184,6 +184,28 @@ void expect_rejects(const char* what, const std::vector<uint8_t>& bytes) { | |||
| 184 | 184 | ||
| 185 | void test_valid_image() { expect_loads("a valid image maps with its section intact", make_image()); } | 185 | void test_valid_image() { expect_loads("a valid image maps with its section intact", make_image()); } |
| 186 | 186 | ||
| 187 | void test_entry_bounds() { | ||
| 188 | for (bool is_dll : {false, true}) { | ||
| 189 | for (uint32_t entry : {0u, 0x1000u, 0x1FFFu, 0x2000u, 0x2001u}) { | ||
| 190 | auto img = make_image(); | ||
| 191 | if (is_dll) nt_of(img)->FileHeader.Characteristics |= IMAGE_FILE_DLL; | ||
| 192 | nt_of(img)->OptionalHeader.AddressOfEntryPoint = entry; | ||
| 193 | const std::string what = std::string(is_dll ? "DLL" : "EXE") + " entry RVA " + std::to_string(entry); | ||
| 194 | if (entry < nt_of(img)->OptionalHeader.SizeOfImage) { | ||
| 195 | expect_loads(what.c_str(), img); | ||
| 196 | } else { | ||
| 197 | std::string error; | ||
| 198 | if (load(write_image(img), error) == 0) | ||
| 199 | failed(what.c_str(), "the image loaded"); | ||
| 200 | else if (error.find("the entry point is outside the image") == std::string::npos) | ||
| 201 | failed(what.c_str(), "unexpected error: " + error); | ||
| 202 | else | ||
| 203 | pass(what.c_str()); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 187 | void test_header_bounds() { | 209 | void test_header_bounds() { |
| 188 | { | 210 | { |
| 189 | auto img = make_image(); | 211 | auto img = make_image(); |
| @@ -1093,6 +1115,7 @@ int main() { | |||
| 1093 | return 1; | 1115 | return 1; |
| 1094 | } | 1116 | } |
| 1095 | test_valid_image(); | 1117 | test_valid_image(); |
| 1118 | test_entry_bounds(); | ||
| 1096 | test_header_bounds(); | 1119 | test_header_bounds(); |
| 1097 | test_section_bounds(); | 1120 | test_section_bounds(); |
| 1098 | test_truncation(); | 1121 | test_truncation(); |