summaryrefslogtreecommitdiffstats
path: root/courgette
diff options
context:
space:
mode:
authorWill Harris <wfh@chromium.org>2015-03-02 13:14:25 -0800
committerWill Harris <wfh@chromium.org>2015-03-02 21:16:44 +0000
commit3e6fa973958cb37622aa882f2c13b6927228e4fc (patch)
tree2aeae1d11bd311a04ed01dca07867ac4160bd72d /courgette
parent94b8fe46a0abf285a0c39cd36007de0236dd7e97 (diff)
downloadchromium_src-3e6fa973958cb37622aa882f2c13b6927228e4fc.zip
chromium_src-3e6fa973958cb37622aa882f2c13b6927228e4fc.tar.gz
chromium_src-3e6fa973958cb37622aa882f2c13b6927228e4fc.tar.bz2
Fix courgette ELF x86 dissembler
Courgette cannot parse files that have out of order NOBITS sections and instead will crash. The solution to this is to skip them and encode them as raw bytes. Also, courgette has a bug where it incorrectly emits ElfRelocationInstruction instructions even when there are no valid R_386_RELATIVE relocations in the file. Added a test file that exhibits both of these symptoms. BUG=424820,423925 TEST=courgette_unittests R=dgarrett@chromium.org, tommi@chromium.org Review URL: https://codereview.chromium.org/664803002 Cr-Commit-Position: refs/heads/master@{#318764}
Diffstat (limited to 'courgette')
-rw-r--r--courgette/disassembler_elf_32.cc5
-rw-r--r--courgette/disassembler_elf_32_x86.cc3
-rw-r--r--courgette/encode_decode_unittest.cc5
-rwxr-xr-xcourgette/testdata/elf-32-high-bssbin0 -> 7160 bytes
4 files changed, 11 insertions, 2 deletions
diff --git a/courgette/disassembler_elf_32.cc b/courgette/disassembler_elf_32.cc
index ff2b9e0..02a31eb 100644
--- a/courgette/disassembler_elf_32.cc
+++ b/courgette/disassembler_elf_32.cc
@@ -262,6 +262,9 @@ CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) {
const Elf32_Shdr *section_header = SectionHeader(section_id);
+ if (section_header->sh_type == SHT_NOBITS)
+ continue;
+
if (!ParseSimpleRegion(file_offset,
section_header->sh_offset,
program))
@@ -282,8 +285,6 @@ CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) {
return false;
file_offset = section_header->sh_offset + section_header->sh_size;
break;
- case SHT_NOBITS:
- // Fall through
case SHT_INIT_ARRAY:
// Fall through
case SHT_FINI_ARRAY:
diff --git a/courgette/disassembler_elf_32_x86.cc b/courgette/disassembler_elf_32_x86.cc
index 74496d3..d2c1c86 100644
--- a/courgette/disassembler_elf_32_x86.cc
+++ b/courgette/disassembler_elf_32_x86.cc
@@ -91,6 +91,9 @@ CheckBool DisassemblerElf32X86::ParseRelocationSection(
uint32 section_relocs_count = section_header->sh_size /
section_header->sh_entsize;
+ if (abs32_locations_.empty())
+ match = false;
+
if (abs32_locations_.size() > section_relocs_count)
match = false;
diff --git a/courgette/encode_decode_unittest.cc b/courgette/encode_decode_unittest.cc
index 0e121d6..a3161ce 100644
--- a/courgette/encode_decode_unittest.cc
+++ b/courgette/encode_decode_unittest.cc
@@ -82,3 +82,8 @@ TEST_F(EncodeDecodeTest, Elf_Small) {
std::string file = FileContents("elf-32-1");
TestAssembleToStreamDisassemble(file, 135988);
}
+
+TEST_F(EncodeDecodeTest, Elf_HighBSS) {
+ std::string file = FileContents("elf-32-high-bss");
+ TestAssembleToStreamDisassemble(file, 7308);
+}
diff --git a/courgette/testdata/elf-32-high-bss b/courgette/testdata/elf-32-high-bss
new file mode 100755
index 0000000..b9445c8
--- /dev/null
+++ b/courgette/testdata/elf-32-high-bss
Binary files differ