mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-03 19:15:30 +00:00
[Object/ELF] - Do not crash on invalid sh_offset value of REL[A] section.
Previously code would access invalid memory and may crash, patch fixes the issue. Differential revision: https://reviews.llvm.org/D25187 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283204 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e1a1a52945
commit
cd988cd581
@ -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);
|
||||
}
|
||||
|
||||
|
BIN
test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-i386
Normal file
BIN
test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-i386
Normal file
Binary file not shown.
BIN
test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64
Normal file
BIN
test/Object/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64
Normal file
Binary file not shown.
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user