diff options
author | Kevin Enderby <enderby@apple.com> | 2016-08-05 18:19:40 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-08-05 18:19:40 +0000 |
commit | 600fb3f28eb5e1a3ad5e04118e74cdd65def4aa3 (patch) | |
tree | 82243b582e31930d055fd580daeff2a8f3c1f75b /llvm/lib/Object/MachOObjectFile.cpp | |
parent | 0f4f0c5d5378703a7d0156120ddf75e3546e41b1 (diff) | |
download | bcm5719-llvm-600fb3f28eb5e1a3ad5e04118e74cdd65def4aa3.tar.gz bcm5719-llvm-600fb3f28eb5e1a3ad5e04118e74cdd65def4aa3.zip |
Add the first of what will be a long line of additional error checks for invalid Mach-O files.
This is where an LC_SEGMENT load command has a fileoff field that
extends past the end of the file.
Also fix llvm-nm and llvm-size to remove the errorToErrorCode() call so error messages are printed.
And needed to update a few test cases now that they do print the error messages just a
bit differently.
llvm-svn: 277845
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 262dbe12ed4..863081fbd4c 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -241,6 +241,11 @@ static Error parseSegmentLoadCommand( const char *Sec = getSectionPtr(Obj, Load, J); Sections.push_back(Sec); } + uint64_t FileSize = Obj->getData().size(); + if (S.fileoff > FileSize) + return malformedError("load command " + Twine(LoadCommandIndex) + + " fileoff field in " + CmdName + + " extends past the end of the file"); IsPageZeroSegment |= StringRef("__PAGEZERO").equals(S.segname); } else return SegOrErr.takeError(); |