]> granicus.if.org Git - llvm/commitdiff
Next set of additional error checks for invalid Mach-O files for bad LC_UUID
authorKevin Enderby <enderby@apple.com>
Wed, 21 Sep 2016 20:03:09 +0000 (20:03 +0000)
committerKevin Enderby <enderby@apple.com>
Wed, 21 Sep 2016 20:03:09 +0000 (20:03 +0000)
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

lib/Object/MachOObjectFile.cpp
test/Object/Inputs/macho-invalid-uuid-bad-size [new file with mode: 0644]
test/Object/Inputs/macho-invalid-uuid-more-than-one [new file with mode: 0644]
test/Object/macho-invalid.test

index 1592e49a10b4da7c869e364bad23656fc5fc2d7d..da5a313f4b1724d10189b961df53bec9019de7e3 100644 (file)
@@ -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 (file)
index 0000000..6e7351e
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 (file)
index 0000000..5427811
Binary files /dev/null and b/test/Object/Inputs/macho-invalid-uuid-more-than-one differ
index b8a1e10148f441b557d68b7a9d7655c980760e80..64899d7612620ba808ce440b18ec14e095af4766 100644 (file)
@@ -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)