From 600fb3f28eb5e1a3ad5e04118e74cdd65def4aa3 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Fri, 5 Aug 2016 18:19:40 +0000 Subject: 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 --- llvm/lib/Object/MachOObjectFile.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/Object/MachOObjectFile.cpp') diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 262dbe1..863081f 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(); -- cgit v1.1