1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[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
This commit is contained in:
Alexey Samsonov 2015-06-04 22:26:44 +00:00
parent e76e79548b
commit 7239805bf0
3 changed files with 7 additions and 1 deletions

View File

@ -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 ||

View File

@ -37,3 +37,6 @@ INVALID-SECTION-IDX-SYMBOL-SEC: getSymbolSection: Invalid section index
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-header 2>&1 | FileCheck -check-prefix INVALID-HEADER %s
INVALID-HEADER: Invalid data was encountered while parsing the file
RUN: not llvm-objdump -private-headers %p/Inputs/macho64-invalid-incomplete-segment-load-command 2>&1 | FileCheck -check-prefix INCOMPLETE-SEGMENT-LOADC %s
INCOMPLETE-SEGMENT-LOADC: Invalid data was encountered while parsing the file