diff options
-rw-r--r-- | llvm/include/llvm/Object/ELF.h | 4 | ||||
-rw-r--r-- | llvm/test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-i386 | bin | 0 -> 358 bytes | |||
-rw-r--r-- | llvm/test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 | bin | 0 -> 543 bytes | |||
-rw-r--r-- | llvm/test/Object/invalid.test | 6 |
4 files changed, 10 insertions, 0 deletions
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h index b08b427b811..586f9d643c3 100644 --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -137,6 +137,8 @@ public: const Elf_Rela *rela_begin(const Elf_Shdr *sec) const { if (sec->sh_entsize != sizeof(Elf_Rela)) report_fatal_error("Invalid relocation entry size"); + if (sec->sh_offset >= Buf.size()) + report_fatal_error("Invalid relocation entry offset"); return reinterpret_cast<const Elf_Rela *>(base() + sec->sh_offset); } @@ -154,6 +156,8 @@ public: const Elf_Rel *rel_begin(const Elf_Shdr *sec) const { if (sec->sh_entsize != sizeof(Elf_Rel)) report_fatal_error("Invalid relocation entry size"); + if (sec->sh_offset >= Buf.size()) + report_fatal_error("Invalid relocation entry offset"); return reinterpret_cast<const Elf_Rel *>(base() + sec->sh_offset); } diff --git a/llvm/test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-i386 b/llvm/test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-i386 Binary files differnew file mode 100644 index 00000000000..84fcd0d1d00 --- /dev/null +++ b/llvm/test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-i386 diff --git a/llvm/test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 b/llvm/test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 Binary files differnew file mode 100644 index 00000000000..aae6c1e9c1c --- /dev/null +++ b/llvm/test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 diff --git a/llvm/test/Object/invalid.test b/llvm/test/Object/invalid.test index e19583d4be1..2d5e0e27440 100644 --- a/llvm/test/Object/invalid.test +++ b/llvm/test/Object/invalid.test @@ -58,3 +58,9 @@ INVALID-XINDEX-SIZE: Invalid data was encountered while parsing the file. RUN: not llvm-readobj -t %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \ RUN: FileCheck --check-prefix=INVALID-EXT-SYMTAB-INDEX %s INVALID-EXT-SYMTAB-INDEX: Invalid symbol table index + +RUN: not llvm-readobj -r %p/Inputs/invalid-relocation-sec-sh_offset.elf-i386 2>&1 | \ +RUN: FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s +RUN: not llvm-readobj -r %p/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 2>&1 | \ +RUN: FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s +INVALID-RELOC-SH-OFFSET: Invalid relocation entry offset |