1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

Check alignment in getSectionContentsAsArray.

While the ArrayRef can technically have unaligned data, it would be
extremely surprising if iterating over it caused undefined behavior
when a reference to the underlying type was bound.

llvm-svn: 319392
This commit is contained in:
Rafael Espindola 2017-11-30 00:44:22 +00:00
parent 4aceb25b2c
commit 28dc39af8c
2 changed files with 24 additions and 0 deletions

View File

@ -277,6 +277,9 @@ ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
Offset + Size > Buf.size())
return createError("invalid section offset");
if (Offset % alignof(T))
return createError("unaligned data");
const T *Start = reinterpret_cast<const T *>(base() + Offset);
return makeArrayRef(Start, Size / sizeof(T));
}

View File

@ -0,0 +1,21 @@
# RUN: yaml2obj %s -o %t.o
# RUN: not llvm-readobj -r %t.o 2>&1 | FileCheck %s
# CHECK: Error reading file: unaligned data
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .foo
Type: SHT_PROGBITS
Content: 42
- Name: .rela.foo
Type: SHT_RELA
Info: .foo
Relocations:
- Offset: 0
Type: R_X86_64_NONE