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:
parent
4aceb25b2c
commit
28dc39af8c
@ -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));
|
||||
}
|
||||
|
21
test/Object/invalid-alignment.test
Normal file
21
test/Object/invalid-alignment.test
Normal 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
|
Loading…
Reference in New Issue
Block a user