diff options
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index 73bc49206..f4cfe4103 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -419,6 +419,42 @@ void test_imports() { | |||
| 419 | } | 419 | } |
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | void test_import_name_rvas() { | ||
| 423 | for (bool delay : {false, true}) { | ||
| 424 | auto img = make_import_image("testshim.dll", "F"); | ||
| 425 | if (delay) { | ||
| 426 | std::fill(img.begin() + 0x200, img.begin() + 0x240, uint8_t{0}); | ||
| 427 | auto* d = reinterpret_cast<IMAGE_DELAYLOAD_DESCRIPTOR*>(img.data() + 0x200); | ||
| 428 | d->Attributes.AllAttributes = 1; | ||
| 429 | d->DllNameRVA = 0x1060; | ||
| 430 | d->ImportNameTableRVA = 0x1100; | ||
| 431 | d->ImportAddressTableRVA = 0x1180; | ||
| 432 | auto* nt = nt_of(img); | ||
| 433 | nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] = {}; | ||
| 434 | auto& dir = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT]; | ||
| 435 | dir.VirtualAddress = 0x1000; | ||
| 436 | dir.Size = 2 * sizeof(IMAGE_DELAYLOAD_DESCRIPTOR); | ||
| 437 | } | ||
| 438 | const char* valid = delay ? "a valid delay-import name RVA loads" : "a valid import name RVA loads"; | ||
| 439 | std::string error; | ||
| 440 | if (load(write_image(img), error) != 0) | ||
| 441 | failed(valid, error); | ||
| 442 | else | ||
| 443 | pass(valid); | ||
| 444 | |||
| 445 | *reinterpret_cast<uint64_t*>(img.data() + 0x300) = (1ull << 32) | 0x1120; | ||
| 446 | const char* invalid = delay ? "a delay-import name RVA with high bits is rejected" | ||
| 447 | : "an import name RVA with high bits is rejected"; | ||
| 448 | error.clear(); | ||
| 449 | if (load(write_image(img), error) == 0) | ||
| 450 | failed(invalid, "the image loaded"); | ||
| 451 | else if (error.find("an import name runs past the image") == std::string::npos) | ||
| 452 | failed(invalid, error); | ||
| 453 | else | ||
| 454 | pass(invalid); | ||
| 455 | } | ||
| 456 | } | ||
| 457 | |||
| 422 | void test_delay_imports() { | 458 | void test_delay_imports() { |
| 423 | { | 459 | { |
| 424 | auto img = make_image(); | 460 | auto img = make_image(); |
| @@ -1135,6 +1171,7 @@ int main() { | |||
| 1135 | test_relocations(); | 1171 | test_relocations(); |
| 1136 | test_exports(); | 1172 | test_exports(); |
| 1137 | test_imports(); | 1173 | test_imports(); |
| 1174 | test_import_name_rvas(); | ||
| 1138 | test_delay_imports(); | 1175 | test_delay_imports(); |
| 1139 | test_initialise(); | 1176 | test_initialise(); |
| 1140 | test_initialise_rejects(); | 1177 | test_initialise_rejects(); |