diff options
author | Jake Ehrlich <jakehehrlich@google.com> | 2017-10-10 21:28:22 +0000 |
---|---|---|
committer | Jake Ehrlich <jakehehrlich@google.com> | 2017-10-10 21:28:22 +0000 |
commit | 70bd75f8d8bd396b2b86b89760ee1689d986527d (patch) | |
tree | d926f28e4ed059941c81aefa4462af4cd20f543d /llvm/tools/llvm-objcopy/Object.cpp | |
parent | ef421f9c180296eb890a235726a7a2a4195e8400 (diff) | |
download | bcm5719-llvm-70bd75f8d8bd396b2b86b89760ee1689d986527d.tar.gz bcm5719-llvm-70bd75f8d8bd396b2b86b89760ee1689d986527d.zip |
[llvm-objcopy] Fix latent bug that allowed some Sections to be improperly cast to StringTableSections
If a Section had Type SHT_STRTAB (which could happen if you had a
.dynstr section) it was possible to cast Section to StringTableSection
and get away with any operation that was supported by SectionBase
without it being noticed. This change makes this bug easier to notice
and fixes it where it occurred. It also made me realize that there was
some duplication of efforts in the loop that calls ::initialize. These
issues are all fixed by this change.
Differential Revision: https://reviews.llvm.org/D38329
llvm-svn: 315372
Diffstat (limited to 'llvm/tools/llvm-objcopy/Object.cpp')
-rw-r--r-- | llvm/tools/llvm-objcopy/Object.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/llvm/tools/llvm-objcopy/Object.cpp b/llvm/tools/llvm-objcopy/Object.cpp index bb79e4269d4..2bd3aa16f0b 100644 --- a/llvm/tools/llvm-objcopy/Object.cpp +++ b/llvm/tools/llvm-objcopy/Object.cpp @@ -289,11 +289,14 @@ bool SectionWithStrTab::classof(const SectionBase *S) { } void SectionWithStrTab::initialize(SectionTableRef SecTable) { - setStrTab(SecTable.getSectionOfType<StringTableSection>( - Link, - "Link field value " + Twine(Link) + " in section " + Name + " is invalid", - "Link field value " + Twine(Link) + " in section " + Name + - " is not a string table")); + auto StrTab = SecTable.getSection(Link, + "Link field value " + Twine(Link) + + " in section " + Name + " is invalid"); + if (StrTab->Type != SHT_STRTAB) { + error("Link field value " + Twine(Link) + " in section " + Name + + " is not a string table"); + } + setStrTab(StrTab); } void SectionWithStrTab::finalize() { this->Link = StrTab->Index; } @@ -535,15 +538,6 @@ SectionTableRef Object<ELFT>::readSectionHeaders(const ELFFile<ELFT> &ElfFile) { initRelocations(RelSec, SymbolTable, unwrapOrError(ElfFile.relas(Shdr))); } - - if (auto Sec = dyn_cast<SectionWithStrTab>(Section.get())) { - Sec->setStrTab(SecTable.getSectionOfType<StringTableSection>( - Sec->Link, - "Link field value " + Twine(Sec->Link) + " in section " + Sec->Name + - " is invalid", - "Link field value " + Twine(Sec->Link) + " in section " + Sec->Name + - " is not a string table")); - } } return SecTable; @@ -621,7 +615,7 @@ void Object<ELFT>::writeSectionHeaders(FileOutputBuffer &Out) const { template <class ELFT> void Object<ELFT>::writeSectionData(FileOutputBuffer &Out) const { for (auto &Section : Sections) - Section->writeSection(Out); + Section->writeSection(Out); } template <class ELFT> |