From f8a7bf8c6ebc141ee7e0ae862d67362b946c04b0 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 4 Jun 2015 22:26:44 +0000 Subject: [Object, MachO] Don't crash on incomplete MachO segment load commands. Report proper error code from MachOObjectFile constructor if we can't parse another segment load command (we already return a proper error if segment load command contents is suspicious). llvm-svn: 239109 --- llvm/lib/Object/MachOObjectFile.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Object/MachOObjectFile.cpp') diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index a824db5f34d..dc7c56c98ac 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -207,7 +207,10 @@ static std::error_code parseSegmentLoadCommand( const unsigned SegmentLoadSize = sizeof(SegmentCmd); if (Load.C.cmdsize < SegmentLoadSize) return object_error::macho_load_segment_too_small; - SegmentCmd S = getStruct(Obj, Load.Ptr); + auto SegOrErr = getStructOrErr(Obj, Load.Ptr); + if (!SegOrErr) + return SegOrErr.getError(); + SegmentCmd S = SegOrErr.get(); const unsigned SectionSize = Obj->is64Bit() ? sizeof(MachO::section_64) : sizeof(MachO::section); if (S.nsects > std::numeric_limits::max() / SectionSize || -- cgit v1.2.3