diff options
author | Kevin Enderby <enderby@apple.com> | 2016-07-07 22:11:42 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-07-07 22:11:42 +0000 |
commit | 1851a827a0e93b684345caef6c9b5df09c0c0f96 (patch) | |
tree | 33977fe073e60c78a0d8423be20f6efcfd5fc26f /llvm/lib/Object/MachOObjectFile.cpp | |
parent | a1a36c85df101b68f2c9182dd386c0672708bdda (diff) | |
download | bcm5719-llvm-1851a827a0e93b684345caef6c9b5df09c0c0f96.tar.gz bcm5719-llvm-1851a827a0e93b684345caef6c9b5df09c0c0f96.zip |
Add checks to the MachOObjectFile() constructor to make sure load commands sizes
are the correct multiple.
llvm-svn: 274798
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 3c88f9fb382..563236f95a5 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -297,6 +297,25 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, } for (unsigned I = 0; I < LoadCommandCount; ++I) { + if (is64Bit()) { + if (Load.C.cmdsize % 8 != 0) { + // We have a hack here to allow 64-bit Mach-O core files to have + // LC_THREAD commands that are only a multiple of 4 and not 8 to be + // allowed since the macOS kernel produces them. + if (getHeader().filetype != MachO::MH_CORE || + Load.C.cmd != MachO::LC_THREAD || Load.C.cmdsize % 4) { + Err = malformedError("load command " + Twine(I) + " cmdsize not a " + "multiple of 8"); + return; + } + } + } else { + if (Load.C.cmdsize % 4 != 0) { + Err = malformedError("load command " + Twine(I) + " cmdsize not a " + "multiple of 4"); + return; + } + } LoadCommands.push_back(Load); if (Load.C.cmd == MachO::LC_SYMTAB) { // Multiple symbol tables |