diff options
author | Kevin Enderby <enderby@apple.com> | 2016-05-03 17:16:08 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-05-03 17:16:08 +0000 |
commit | 368e714907127036658626353f7604d91ccbde04 (patch) | |
tree | a1bbb7c21572be01602ee391a8b4a97d083ee4ce /llvm/lib/Object/MachOObjectFile.cpp | |
parent | ec2108199fec3cf0bf623b308bf91e02b6c26433 (diff) | |
download | llvm-368e714907127036658626353f7604d91ccbde04.zip llvm-368e714907127036658626353f7604d91ccbde04.tar.gz llvm-368e714907127036658626353f7604d91ccbde04.tar.bz2 |
Produce another specific error message for a malformed Mach-O file when a load
command other than the first one is past the end of the load commands.
This is like the test case in test/Object/macho-invalid.test for
macho64-invalid-incomplete-load-command but it is the second load command
that is past the end of all the load commands instead of the first.
The code in the constructor for MachOObjectFile that loops over the load
commands used getNextLoadCommandInfo() which was not producing
a good error message. So that was fixed and a test case was added.
llvm-svn: 268403
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 2240dc8..744603a 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -199,8 +199,16 @@ getFirstLoadCommandInfo(const MachOObjectFile *Obj) { } static Expected<MachOObjectFile::LoadCommandInfo> -getNextLoadCommandInfo(const MachOObjectFile *Obj, +getNextLoadCommandInfo(const MachOObjectFile *Obj, uint32_t LoadCommandIndex, const MachOObjectFile::LoadCommandInfo &L) { + unsigned HeaderSize = Obj->is64Bit() ? sizeof(MachO::mach_header_64) + : sizeof(MachO::mach_header); + if (L.Ptr + L.C.cmdsize + sizeof(MachOObjectFile::LoadCommandInfo) > + Obj->getData().data() + HeaderSize + Obj->getHeader().sizeofcmds) + return malformedError(*Obj, Twine("truncated or malformed object " + "(load command ") + Twine(LoadCommandIndex + 1) + + Twine(" extends past the end all load commands in the " + "file)")); return getLoadCommandInfo(Obj, L.Ptr + L.C.cmdsize); } @@ -361,7 +369,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, Libraries.push_back(Load.Ptr); } if (I < LoadCommandCount - 1) { - if (auto LoadOrErr = getNextLoadCommandInfo(this, Load)) + if (auto LoadOrErr = getNextLoadCommandInfo(this, I, Load)) Load = *LoadOrErr; else { Err = LoadOrErr.takeError(); |