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 f4cfe4103..00ef5affd 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -841,6 +841,26 @@ void test_process_detach_dependencies() { | |||
| 841 | g_live_modules.clear(); | 841 | g_live_modules.clear(); |
| 842 | } | 842 | } |
| 843 | 843 | ||
| 844 | // A dependency whose import table is corrupt fails while the parent binds it. Neither must stay findable by name: | ||
| 845 | // a later load or GetModuleHandle would otherwise get a mapped image whose imports were never bound. | ||
| 846 | void test_failed_dependency_not_registered() { | ||
| 847 | const char* what = "a failed load leaves neither the module nor its failed dependency loaded"; | ||
| 848 | auto dep = make_import_image("kernel32.dll", "GetCurrentProcessId"); | ||
| 849 | reinterpret_cast<IMAGE_IMPORT_DESCRIPTOR*>(dep.data() + 0x200)->Name = 0x5000; // past SizeOfImage | ||
| 850 | const auto dep_path = write_image_as(dep, "fail_dep.dll"); | ||
| 851 | const auto parent_path = write_image_as(make_import_image("fail_dep.dll", "x"), "fail_parent.dll"); | ||
| 852 | rt::Loader loader(g_dir); | ||
| 853 | auto throws = [&](const std::filesystem::path& p) { | ||
| 854 | try { loader.load(p); return false; } catch (const std::exception&) { return true; } | ||
| 855 | }; | ||
| 856 | if (!throws(parent_path)) return failed(what, "the parent loaded over a corrupt dependency"); | ||
| 857 | if (loader.find_loaded_module("fail_dep.dll") || loader.find_loaded_module("fail_parent.dll")) | ||
| 858 | return failed(what, "a failed module is still found by name"); | ||
| 859 | if (!throws(dep_path)) return failed(what, "a second load of the dependency returned the half-loaded module"); | ||
| 860 | if (!throws(parent_path)) return failed(what, "a second load of the parent returned the half-loaded module"); | ||
| 861 | pass(what); | ||
| 862 | } | ||
| 863 | |||
| 844 | void test_forwarded_exports() { | 864 | void test_forwarded_exports() { |
| 845 | { | 865 | { |
| 846 | const char* what = "a forwarded export binds to its target instead of into the string"; | 866 | const char* what = "a forwarded export binds to its target instead of into the string"; |
| @@ -1179,6 +1199,7 @@ int main() { | |||
| 1179 | test_process_detach_invalid_tls(); | 1199 | test_process_detach_invalid_tls(); |
| 1180 | test_process_detach_without_entry(); | 1200 | test_process_detach_without_entry(); |
| 1181 | test_process_detach_dependencies(); | 1201 | test_process_detach_dependencies(); |
| 1202 | test_failed_dependency_not_registered(); | ||
| 1182 | test_delay_descriptor_fields(); | 1203 | test_delay_descriptor_fields(); |
| 1183 | test_forwarded_exports(); | 1204 | test_forwarded_exports(); |
| 1184 | test_export_bounds(); | 1205 | test_export_bounds(); |