diff options
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index f16ba5589..194174b00 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -1006,6 +1006,19 @@ void test_unwind_registration() { | |||
| 1006 | expect_rejects("unwind data past the image", make_unwind_image({{0x1000, 0x1010, 0x1FFE}})); | 1006 | expect_rejects("unwind data past the image", make_unwind_image({{0x1000, 0x1010, 0x1FFE}})); |
| 1007 | } | 1007 | } |
| 1008 | 1008 | ||
| 1009 | // An export whose address-table entry is past SizeOfImage (not a forwarder: outside the export directory) is | ||
| 1010 | // refused instead of being stored as base + rva, a pointer outside the mapping. | ||
| 1011 | void test_export_bounds() { | ||
| 1012 | auto outside = make_forwarder_image("KERNEL32.GetCurrentProcessId", 0x180000000); | ||
| 1013 | nt_of(outside)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = sizeof(IMAGE_EXPORT_DIRECTORY); | ||
| 1014 | *reinterpret_cast<uint32_t*>(outside.data() + 0x300) = 0x2000; // funcs[0] == SizeOfImage | ||
| 1015 | expect_rejects("an export whose address is past the image", outside); | ||
| 1016 | auto last = make_forwarder_image("KERNEL32.GetCurrentProcessId", 0x180000000); | ||
| 1017 | nt_of(last)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = sizeof(IMAGE_EXPORT_DIRECTORY); | ||
| 1018 | *reinterpret_cast<uint32_t*>(last.data() + 0x300) = 0x1FFF; // the image's last byte: still inside | ||
| 1019 | expect_loads("an export at the image's last byte still loads", last); | ||
| 1020 | } | ||
| 1021 | |||
| 1009 | // The folder the images go to: leonida_loader_test\<process id> in LEONIDA_TEST_DIR when that is set, otherwise in | 1022 | // The folder the images go to: leonida_loader_test\<process id> in LEONIDA_TEST_DIR when that is set, otherwise in |
| 1010 | // the temporary directory. A folder per run, because security software can hold the previous run's images for a | 1023 | // the temporary directory. A folder per run, because security software can hold the previous run's images for a |
| 1011 | // while after they are written (so they can be neither deleted nor overwritten); the fixed parent name is what an | 1024 | // while after they are written (so they can be neither deleted nor overwritten); the fixed parent name is what an |
| @@ -1095,6 +1108,7 @@ int main() { | |||
| 1095 | test_process_detach_dependencies(); | 1108 | test_process_detach_dependencies(); |
| 1096 | test_delay_descriptor_fields(); | 1109 | test_delay_descriptor_fields(); |
| 1097 | test_forwarded_exports(); | 1110 | test_forwarded_exports(); |
| 1111 | test_export_bounds(); | ||
| 1098 | test_unwind_registration(); | 1112 | test_unwind_registration(); |
| 1099 | } catch (const std::exception& e) { | 1113 | } catch (const std::exception& e) { |
| 1100 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. | 1114 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. |