Fix endian issue when creating sectionsByOldIndex

sectionsByOldIndex was resized to hdr->e_shnum instead of
rdi(hdr->e_shnum). This omitted the endianness conversion and probably
only worked by accident, because the 16-bit LE->BE conversion results
in integers that are larger as long as there no more than 255 section
headers.

This would be a good usecase for std::transform, but I'm unsure
whether we want to bump requirements to build patchelf to C++ 2017.
This commit is contained in:
Julian Stecklina
2020-11-15 16:04:17 +01:00
parent 52e9dd5900
commit d148bae6c1

View File

@@ -447,8 +447,8 @@ ElfFile<ElfFileParamNames>::ElfFile(FileContents fileContents)
sectionNames = std::string(shstrtab, shstrtabSize);
sectionsByOldIndex.resize(hdr->e_shnum);
for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i)
sectionsByOldIndex.resize(shdrs.size());
for (size_t i = 1; i < shdrs.size(); ++i)
sectionsByOldIndex[i] = getSectionName(shdrs[i]);
}