Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Unified Diff: courgette/disassembler_elf_32.cc

Issue 1870293002: [Courgette] Sort section headers by sh_offset in ELF flows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « courgette/disassembler_elf_32.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/disassembler_elf_32.cc
diff --git a/courgette/disassembler_elf_32.cc b/courgette/disassembler_elf_32.cc
index 70294d6f27bfd0cd7b8456024516943cd06f461d..346d9a19906fbc4291464ff34027527639386423 100644
--- a/courgette/disassembler_elf_32.cc
+++ b/courgette/disassembler_elf_32.cc
@@ -12,10 +12,27 @@
namespace courgette {
+namespace {
+
+// Initializes |section_header_table| by copying |section_header_table_size|
+// entries from |section_header_table_raw|, and sorting by |sh_offset|.
+void SortSectionHeader(const Elf32_Shdr* section_header_table_raw,
+ Elf32_Half section_header_table_size,
+ std::vector<Elf32_Shdr>* section_header_table) {
+ section_header_table->assign(section_header_table_raw,
+ section_header_table_raw + section_header_table_size);
+ auto comp = [](const Elf32_Shdr& header1, const Elf32_Shdr& header2) {
+ return header1.sh_offset < header2.sh_offset;
+ };
+ std::stable_sort(
+ section_header_table->begin(), section_header_table->end(), comp);
+}
+
+} // namespace
+
DisassemblerElf32::DisassemblerElf32(const void* start, size_t length)
: Disassembler(start, length),
header_(nullptr),
- section_header_table_(nullptr),
section_header_table_size_(0),
program_header_table_(nullptr),
program_header_table_size_(0),
@@ -95,9 +112,12 @@ bool DisassemblerElf32::ParseHeader() {
if (!IsArrayInBounds(header_->e_shoff, header_->e_shnum, sizeof(Elf32_Shdr)))
return Bad("Out of bounds section header table");
- section_header_table_ = reinterpret_cast<const Elf32_Shdr*>(
- FileOffsetToPointer(header_->e_shoff));
+ const Elf32_Shdr* section_header_table_raw =
+ reinterpret_cast<const Elf32_Shdr*>(
+ FileOffsetToPointer(header_->e_shoff));
section_header_table_size_ = header_->e_shnum;
+ SortSectionHeader(section_header_table_raw, section_header_table_size_,
+ &section_header_table_);
if (!IsArrayInBounds(header_->e_phoff, header_->e_phnum, sizeof(Elf32_Phdr)))
return Bad("Out of bounds program header table");
« no previous file with comments | « courgette/disassembler_elf_32.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698