diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 1592e49a10b..da5a313f4b1 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -717,9 +717,13 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, "LC_DYLD_INFO_ONLY"))) return; } else if (Load.C.cmd == MachO::LC_UUID) { - // Multiple UUID load commands + if (Load.C.cmdsize != sizeof(MachO::uuid_command)) { + Err = malformedError("LC_UUID command " + Twine(I) + " has incorrect " + "cmdsize"); + return; + } if (UuidLoadCmd) { - Err = malformedError("Multiple UUID load commands"); + Err = malformedError("more than one LC_UUID command"); return; } UuidLoadCmd = Load.Ptr; diff --git a/test/Object/Inputs/macho-invalid-uuid-bad-size b/test/Object/Inputs/macho-invalid-uuid-bad-size new file mode 100644 index 00000000000..6e7351e76b3 Binary files /dev/null and b/test/Object/Inputs/macho-invalid-uuid-bad-size differ diff --git a/test/Object/Inputs/macho-invalid-uuid-more-than-one b/test/Object/Inputs/macho-invalid-uuid-more-than-one new file mode 100644 index 00000000000..5427811a9a4 Binary files /dev/null and b/test/Object/Inputs/macho-invalid-uuid-more-than-one differ diff --git a/test/Object/macho-invalid.test b/test/Object/macho-invalid.test index b8a1e10148f..64899d76126 100644 --- a/test/Object/macho-invalid.test +++ b/test/Object/macho-invalid.test @@ -283,3 +283,9 @@ INVALID-DYLIB-WRONG-FILETYPE: macho-invalid-dylib-wrong-filetype': truncated or RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-dylib-no-id 2>&1 | FileCheck -check-prefix INVALID-DYLIB-NO-ID %s INVALID-DYLIB-NO-ID: macho-invalid-dylib-no-id': truncated or malformed object (no LC_ID_DYLIB load command in dynamic library filetype) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-uuid-more-than-one 2>&1 | FileCheck -check-prefix INVALID-UUID-MORE-THAN-ONE %s +INVALID-UUID-MORE-THAN-ONE: macho-invalid-uuid-more-than-one': truncated or malformed object (more than one LC_UUID command) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-uuid-bad-size 2>&1 | FileCheck -check-prefix INVALID-UUID-BAD-SIZE %s +INVALID-UUID-BAD-SIZE: macho-invalid-uuid-bad-size': truncated or malformed object (LC_UUID command 0 has incorrect cmdsize)