Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit e10e0e3

Browse files
committed
Next set of additional error checks for invalid Mach-O files for bad LC_UUID
load commands. Added a missing check and made the check for more than one like other other “more than one” checks. And of course added test cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282104 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 799bfde commit e10e0e3

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

lib/Object/MachOObjectFile.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,13 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
717717
"LC_DYLD_INFO_ONLY")))
718718
return;
719719
} else if (Load.C.cmd == MachO::LC_UUID) {
720-
// Multiple UUID load commands
720+
if (Load.C.cmdsize != sizeof(MachO::uuid_command)) {
721+
Err = malformedError("LC_UUID command " + Twine(I) + " has incorrect "
722+
"cmdsize");
723+
return;
724+
}
721725
if (UuidLoadCmd) {
722-
Err = malformedError("Multiple UUID load commands");
726+
Err = malformedError("more than one LC_UUID command");
723727
return;
724728
}
725729
UuidLoadCmd = Load.Ptr;
48 Bytes
Binary file not shown.
Binary file not shown.

test/Object/macho-invalid.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,9 @@ INVALID-DYLIB-WRONG-FILETYPE: macho-invalid-dylib-wrong-filetype': truncated or
283283

284284
RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-dylib-no-id 2>&1 | FileCheck -check-prefix INVALID-DYLIB-NO-ID %s
285285
INVALID-DYLIB-NO-ID: macho-invalid-dylib-no-id': truncated or malformed object (no LC_ID_DYLIB load command in dynamic library filetype)
286+
287+
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
288+
INVALID-UUID-MORE-THAN-ONE: macho-invalid-uuid-more-than-one': truncated or malformed object (more than one LC_UUID command)
289+
290+
RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-uuid-bad-size 2>&1 | FileCheck -check-prefix INVALID-UUID-BAD-SIZE %s
291+
INVALID-UUID-BAD-SIZE: macho-invalid-uuid-bad-size': truncated or malformed object (LC_UUID command 0 has incorrect cmdsize)

0 commit comments

Comments
 (0)