This is an archive of the discontinued LLVM Phabricator instance.

[Object/ELF] - Check Header->e_shoff value earlier and do not crash.
ClosedPublic

Authored by grimar on Oct 11 2016, 3:06 AM.

Details

Summary

I had to revert D25368 (r283858, r283740) because it was the reason of UBSan failture:
(http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/17075)

Exit Code: 1

Command Output (stderr):

/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/test/Object/invalid.test:70:32: error: expected string not found in input
INVALID-SEC-ADDRESS-ALIGNMENT: Invalid address alignment of section headers

^

<stdin>:1:1: note: scanning from here
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Object/ELF.h:412:7: runtime error: upcast of misaligned address 0x000002d8b899 for type 'llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<llvm::support::endianness::little, true> >', which requires 2 byte alignment
^
<stdin>:1:125: note: possible intended match here
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Object/ELF.h:412:7: runtime error: upcast of misaligned address 0x000002d8b899 for type 'llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<llvm::support::endianness::little, true> >', which requires 2 byte alignment

Problem is seems to be that on the moment of following call, Section pointer is unaligned:

ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const

Patch moves the alignment check before such call to fix the issue.

Diff Detail

Event Timeline

grimar updated this revision to Diff 74205.Oct 11 2016, 3:06 AM
grimar retitled this revision from to [Object/ELF] - Check Header->e_shoff value earlier and do not crash..
grimar updated this object.
grimar added reviewers: rafael, davide.
grimar updated this object.
grimar added subscribers: llvm-commits, grimar, evgeny777.
rafael accepted this revision.Oct 17 2016, 7:03 AM
rafael edited edge metadata.

LGTM

This revision is now accepted and ready to land.Oct 17 2016, 7:03 AM
This revision was automatically updated to reflect the committed changes.