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 fd38434c6..2e4a32aa8 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -977,6 +977,19 @@ void test_unwind_registration() { | |||
| 977 | expect_rejects("unwind data past the image", make_unwind_image({{0x1000, 0x1010, 0x1FFE}})); | 977 | expect_rejects("unwind data past the image", make_unwind_image({{0x1000, 0x1010, 0x1FFE}})); |
| 978 | } | 978 | } |
| 979 | 979 | ||
| 980 | // An export whose address-table entry is past SizeOfImage (not a forwarder: outside the export directory) is | ||
| 981 | // refused instead of being stored as base + rva, a pointer outside the mapping. | ||
| 982 | void test_export_bounds() { | ||
| 983 | auto outside = make_forwarder_image("KERNEL32.GetCurrentProcessId", 0x180000000); | ||
| 984 | nt_of(outside)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = sizeof(IMAGE_EXPORT_DIRECTORY); | ||
| 985 | *reinterpret_cast<uint32_t*>(outside.data() + 0x300) = 0x2000; // funcs[0] == SizeOfImage | ||
| 986 | expect_rejects("an export whose address is past the image", outside); | ||
| 987 | auto last = make_forwarder_image("KERNEL32.GetCurrentProcessId", 0x180000000); | ||
| 988 | nt_of(last)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = sizeof(IMAGE_EXPORT_DIRECTORY); | ||
| 989 | *reinterpret_cast<uint32_t*>(last.data() + 0x300) = 0x1FFF; // the image's last byte: still inside | ||
| 990 | expect_loads("an export at the image's last byte still loads", last); | ||
| 991 | } | ||
| 992 | |||
| 980 | // The folder the images go to: leonida_loader_test\<process id> in LEONIDA_TEST_DIR when that is set, otherwise in | 993 | // The folder the images go to: leonida_loader_test\<process id> in LEONIDA_TEST_DIR when that is set, otherwise in |
| 981 | // the temporary directory. A folder per run, because security software can hold the previous run's images for a | 994 | // the temporary directory. A folder per run, because security software can hold the previous run's images for a |
| 982 | // while after they are written (so they can be neither deleted nor overwritten); the fixed parent name is what an | 995 | // while after they are written (so they can be neither deleted nor overwritten); the fixed parent name is what an |
| @@ -1066,6 +1079,7 @@ int main() { | |||
| 1066 | test_process_detach_dependencies(); | 1079 | test_process_detach_dependencies(); |
| 1067 | test_delay_descriptor_fields(); | 1080 | test_delay_descriptor_fields(); |
| 1068 | test_forwarded_exports(); | 1081 | test_forwarded_exports(); |
| 1082 | test_export_bounds(); | ||
| 1069 | test_unwind_registration(); | 1083 | test_unwind_registration(); |
| 1070 | } catch (const std::exception& e) { | 1084 | } catch (const std::exception& e) { |
| 1071 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. | 1085 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. |