summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2015-06-04 22:26:44 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2015-06-04 22:26:44 +0000
commitf8a7bf8c6ebc141ee7e0ae862d67362b946c04b0 (patch)
tree2065bae48d425deceec4f4c45f0c71192fab684d /llvm/lib/Object/MachOObjectFile.cpp
parent36e60e9127374c83f2eb7c705d1bd0dcb2a54d18 (diff)
downloadbcm5719-llvm-f8a7bf8c6ebc141ee7e0ae862d67362b946c04b0.tar.gz
bcm5719-llvm-f8a7bf8c6ebc141ee7e0ae862d67362b946c04b0.zip
[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
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp5
1 files changed, 4 insertions, 1 deletions
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<SegmentCmd>(Obj, Load.Ptr);
+ auto SegOrErr = getStructOrErr<SegmentCmd>(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<uint32_t>::max() / SectionSize ||
OpenPOWER on IntegriCloud