diff options
author | Kevin Enderby <enderby@apple.com> | 2016-05-05 17:43:35 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-05-05 17:43:35 +0000 |
commit | b34e3a1877fb095b0386c7e3675aca66ff26edeb (patch) | |
tree | 8b7feb2abd31e5cae269ee6525fa3613d142a804 /llvm/lib/Object/MachOObjectFile.cpp | |
parent | 226a734f1a21db545d24135d6714bda31a08d78b (diff) | |
download | bcm5719-llvm-b34e3a1877fb095b0386c7e3675aca66ff26edeb.tar.gz bcm5719-llvm-b34e3a1877fb095b0386c7e3675aca66ff26edeb.zip |
Clean up the specific error message for a malformed Mach-O files with bad segment
load commands.
The existing test case in test/Object/macho-invalid.test for
macho-invalid-too-small-segment-load-command has a cmdsize of 55, while
being too small also it is not a multiple of 4. So when that check is added
this test case will produce a different error. So I constructed a new test case
that will trigger the intended error.
I also changed the error message to be consistent with the other malformed Mach-O
file error messages which prints the load command index. I also removed both
object_error::macho_load_segment_too_small and
object_error::macho_load_segment_too_many_sections from Object/Error.h
as they are not needed and can just use object_error::parse_failed and let the
error message string distinguish the specific error.
llvm-svn: 268652
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index ad29d0042e3..516607dea23 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -234,22 +234,23 @@ static void parseHeader(const MachOObjectFile *Obj, T &Header, template <typename SegmentCmd> static Error parseSegmentLoadCommand( const MachOObjectFile *Obj, const MachOObjectFile::LoadCommandInfo &Load, - SmallVectorImpl<const char *> &Sections, bool &IsPageZeroSegment) { + SmallVectorImpl<const char *> &Sections, bool &IsPageZeroSegment, + uint32_t LoadCommandIndex, const char *CmdName) { const unsigned SegmentLoadSize = sizeof(SegmentCmd); if (Load.C.cmdsize < SegmentLoadSize) - return malformedError(*Obj, - "Mach-O segment load command size is too small", - object_error::macho_load_segment_too_small); + return malformedError(*Obj, Twine("truncated or malformed object " + "(load command ") + Twine(LoadCommandIndex) + + Twine(" ") + CmdName + Twine(" cmdsize too small)")); if (auto SegOrErr = getStructOrErr<SegmentCmd>(Obj, Load.Ptr)) { SegmentCmd S = SegOrErr.get(); const unsigned SectionSize = Obj->is64Bit() ? sizeof(MachO::section_64) : sizeof(MachO::section); if (S.nsects > std::numeric_limits<uint32_t>::max() / SectionSize || S.nsects * SectionSize > Load.C.cmdsize - SegmentLoadSize) - return malformedError(*Obj, - "Mach-O segment load command contains too many " - "sections", - object_error::macho_load_segment_too_many_sections); + return malformedError(*Obj, Twine("truncated or malformed object " + "(load command ") + Twine(LoadCommandIndex) + + Twine(" inconsistent cmdsize in ") + CmdName + + Twine(" for the number of sections)")); for (unsigned J = 0; J < S.nsects; ++J) { const char *Sec = getSectionPtr(Obj, Load, J); Sections.push_back(Sec); @@ -357,11 +358,12 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, UuidLoadCmd = Load.Ptr; } else if (Load.C.cmd == MachO::LC_SEGMENT_64) { if ((Err = parseSegmentLoadCommand<MachO::segment_command_64>( - this, Load, Sections, HasPageZeroSegment))) + this, Load, Sections, HasPageZeroSegment, I, + "LC_SEGMENT_64"))) return; } else if (Load.C.cmd == MachO::LC_SEGMENT) { if ((Err = parseSegmentLoadCommand<MachO::segment_command>( - this, Load, Sections, HasPageZeroSegment))) + this, Load, Sections, HasPageZeroSegment, I, "LC_SEGMENT"))) return; } else if (Load.C.cmd == MachO::LC_LOAD_DYLIB || Load.C.cmd == MachO::LC_LOAD_WEAK_DYLIB || |