diff options
author | Kevin Enderby <enderby@apple.com> | 2015-10-09 16:48:44 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2015-10-09 16:48:44 +0000 |
commit | af7c9d012322017d841a244e53433b9de27a3452 (patch) | |
tree | 5256f8e16d7d34541c74bead36385454d19a94d3 /llvm/tools/llvm-objdump/MachODump.cpp | |
parent | 3a1ad3970286c029a84f4b1e2e41cf8ae6c2b94b (diff) | |
download | llvm-af7c9d012322017d841a244e53433b9de27a3452.zip llvm-af7c9d012322017d841a244e53433b9de27a3452.tar.gz llvm-af7c9d012322017d841a244e53433b9de27a3452.tar.bz2 |
Fixed two bugs in llvm-objdump’s printing of Objective-C meta data
from malformed Mach-O files that caused crashes. The first because the
offset in a dyld bind table entry was out of range. The second because their
was no image info section and the routine printing it did not have the
need check to see the section did not exist.
rdar://22983603
llvm-svn: 249845
Diffstat (limited to 'llvm/tools/llvm-objdump/MachODump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/MachODump.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index 993e9e6..9682e4a 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -4984,6 +4984,9 @@ static void print_image_info64(SectionRef S, struct DisassembleInfo *info) { struct objc_image_info64 o; const char *r; + if (S == SectionRef()) + return; + StringRef SectName; S.getName(SectName); DataRefImpl Ref = S.getRawDataRefImpl(); @@ -8498,6 +8501,7 @@ public: StringRef segmentName(uint32_t SegIndex); StringRef sectionName(uint32_t SegIndex, uint64_t SegOffset); uint64_t address(uint32_t SegIndex, uint64_t SegOffset); + bool isValidSegIndexAndOffset(uint32_t SegIndex, uint64_t SegOffset); private: struct SectionInfo { @@ -8546,6 +8550,20 @@ StringRef SegInfo::segmentName(uint32_t SegIndex) { llvm_unreachable("invalid segIndex"); } +bool SegInfo::isValidSegIndexAndOffset(uint32_t SegIndex, + uint64_t OffsetInSeg) { + for (const SectionInfo &SI : Sections) { + if (SI.SegmentIndex != SegIndex) + continue; + if (SI.OffsetInSegment > OffsetInSeg) + continue; + if (OffsetInSeg >= (SI.OffsetInSegment + SI.Size)) + continue; + return true; + } + return false; +} + const SegInfo::SectionInfo &SegInfo::findSection(uint32_t SegIndex, uint64_t OffsetInSeg) { for (const SectionInfo &SI : Sections) { @@ -8714,6 +8732,8 @@ static const char *get_dyld_bind_info_symbolname(uint64_t ReferenceValue, for (const llvm::object::MachOBindEntry &Entry : info->O->bindTable()) { uint32_t SegIndex = Entry.segmentIndex(); uint64_t OffsetInSeg = Entry.segmentOffset(); + if (!sectionTable.isValidSegIndexAndOffset(SegIndex, OffsetInSeg)) + continue; uint64_t Address = sectionTable.address(SegIndex, OffsetInSeg); const char *SymbolName = nullptr; StringRef name = Entry.symbolName(); |