diff options
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index 194174b00..c86ade637 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -783,6 +783,26 @@ void test_process_detach_dependencies() { | |||
| 783 | g_live_modules.clear(); | 783 | g_live_modules.clear(); |
| 784 | } | 784 | } |
| 785 | 785 | ||
| 786 | // A dependency whose import table is corrupt fails while the parent binds it. Neither must stay findable by name: | ||
| 787 | // a later load or GetModuleHandle would otherwise get a mapped image whose imports were never bound. | ||
| 788 | void test_failed_dependency_not_registered() { | ||
| 789 | const char* what = "a failed load leaves neither the module nor its failed dependency loaded"; | ||
| 790 | auto dep = make_import_image("kernel32.dll", "GetCurrentProcessId"); | ||
| 791 | reinterpret_cast<IMAGE_IMPORT_DESCRIPTOR*>(dep.data() + 0x200)->Name = 0x5000; // past SizeOfImage | ||
| 792 | const auto dep_path = write_image_as(dep, "fail_dep.dll"); | ||
| 793 | const auto parent_path = write_image_as(make_import_image("fail_dep.dll", "x"), "fail_parent.dll"); | ||
| 794 | rt::Loader loader(g_dir); | ||
| 795 | auto throws = [&](const std::filesystem::path& p) { | ||
| 796 | try { loader.load(p); return false; } catch (const std::exception&) { return true; } | ||
| 797 | }; | ||
| 798 | if (!throws(parent_path)) return failed(what, "the parent loaded over a corrupt dependency"); | ||
| 799 | if (loader.find_loaded_module("fail_dep.dll") || loader.find_loaded_module("fail_parent.dll")) | ||
| 800 | return failed(what, "a failed module is still found by name"); | ||
| 801 | if (!throws(dep_path)) return failed(what, "a second load of the dependency returned the half-loaded module"); | ||
| 802 | if (!throws(parent_path)) return failed(what, "a second load of the parent returned the half-loaded module"); | ||
| 803 | pass(what); | ||
| 804 | } | ||
| 805 | |||
| 786 | void test_forwarded_exports() { | 806 | void test_forwarded_exports() { |
| 787 | { | 807 | { |
| 788 | const char* what = "a forwarded export binds to its target instead of into the string"; | 808 | const char* what = "a forwarded export binds to its target instead of into the string"; |
| @@ -1106,6 +1126,7 @@ int main() { | |||
| 1106 | test_process_detach_invalid_tls(); | 1126 | test_process_detach_invalid_tls(); |
| 1107 | test_process_detach_without_entry(); | 1127 | test_process_detach_without_entry(); |
| 1108 | test_process_detach_dependencies(); | 1128 | test_process_detach_dependencies(); |
| 1129 | test_failed_dependency_not_registered(); | ||
| 1109 | test_delay_descriptor_fields(); | 1130 | test_delay_descriptor_fields(); |
| 1110 | test_forwarded_exports(); | 1131 | test_forwarded_exports(); |
| 1111 | test_export_bounds(); | 1132 | test_export_bounds(); |