Assert library name index is in range of the string table

As suggested by @DrChat
This commit is contained in:
x1nixmzeng 2016-01-09 17:55:57 +00:00
parent 06f259c87d
commit 3eb602c93a
1 changed files with 8 additions and 4 deletions

View File

@ -242,13 +242,15 @@ bool XexModule::Load(const std::string& name, const std::string& path,
// FIXME: Don't know if 32 is the actual limit, but haven't seen more than 2. // FIXME: Don't know if 32 is the actual limit, but haven't seen more than 2.
const char* string_table[32]; const char* string_table[32];
std::memset(string_table, 0, sizeof(string_table)); std::memset(string_table, 0, sizeof(string_table));
size_t max_string_table_index = 0;
// Parse the string table // Parse the string table
for (size_t i = 0, j = 0; i < opt_import_header->string_table_size; j++) { for (size_t i = 0; i < opt_import_header->string_table_size;
assert_true(j < xe::countof(string_table)); ++max_string_table_index) {
assert_true(max_string_table_index < xe::countof(string_table));
const char* str = opt_import_header->string_table + i; const char* str = opt_import_header->string_table + i;
string_table[j] = str; string_table[max_string_table_index] = str;
i += std::strlen(str) + 1; i += std::strlen(str) + 1;
// Padding // Padding
@ -264,7 +266,9 @@ bool XexModule::Load(const std::string& name, const std::string& path,
for (uint32_t i = 0; i < library_count; i++) { for (uint32_t i = 0; i < library_count; i++) {
auto library = auto library =
reinterpret_cast<xex2_import_library*>(libraries_ptr + library_offset); reinterpret_cast<xex2_import_library*>(libraries_ptr + library_offset);
SetupLibraryImports(string_table[library->name_index & 0xFF], library); size_t library_name_index = library->name_index & 0xFF;
assert_true(library_name_index < max_string_table_index);
SetupLibraryImports(string_table[library_name_index], library);
library_offset += library->size; library_offset += library->size;
} }