From a8e3ab0c5675d0e51b5643146fd634cf9608b6f4 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Tue, 3 May 2016 23:13:50 +0000 Subject: Produce another specific error message for a malformed Mach-O file when a load command has a size less than 8 bytes. I think the existing test case in test/Object/macho-invalid.test for macho64-invalid-too-small-load-command was trying to test for this but that test case triggered a different error given how it was constructed. So I constructed a new test case that would trigger this specific error. I also changed the error message to be consistent with the other malformed Mach-O file error messages. I also removed object_error::macho_small_load_command from Object/Error.h as it is not needed and can just use object_error::parse_failed and let the error message string distinguish the error. llvm-svn: 268463 --- llvm/lib/Object/MachOObjectFile.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Object/MachOObjectFile.cpp') diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 744603a..ad29d00 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -177,11 +177,13 @@ static uint32_t getSectionFlags(const MachOObjectFile *O, } static Expected -getLoadCommandInfo(const MachOObjectFile *Obj, const char *Ptr) { +getLoadCommandInfo(const MachOObjectFile *Obj, const char *Ptr, + uint32_t LoadCommandIndex) { if (auto CmdOrErr = getStructOrErr(Obj, Ptr)) { if (CmdOrErr->cmdsize < 8) - return malformedError(*Obj, "Mach-O load command with size < 8 bytes", - object_error::macho_small_load_command); + return malformedError(*Obj, Twine("truncated or malformed object (load " + "command ") + Twine(LoadCommandIndex) + + Twine(" with size less than 8 bytes)")); return MachOObjectFile::LoadCommandInfo({Ptr, *CmdOrErr}); } else return CmdOrErr.takeError(); @@ -195,7 +197,7 @@ getFirstLoadCommandInfo(const MachOObjectFile *Obj) { return malformedError(*Obj, "truncated or malformed object (load command " "0 extends past the end all load commands in the " "file)"); - return getLoadCommandInfo(Obj, getPtr(Obj, HeaderSize)); + return getLoadCommandInfo(Obj, getPtr(Obj, HeaderSize), 0); } static Expected @@ -209,7 +211,7 @@ getNextLoadCommandInfo(const MachOObjectFile *Obj, uint32_t LoadCommandIndex, "(load command ") + Twine(LoadCommandIndex + 1) + Twine(" extends past the end all load commands in the " "file)")); - return getLoadCommandInfo(Obj, L.Ptr + L.C.cmdsize); + return getLoadCommandInfo(Obj, L.Ptr + L.C.cmdsize, LoadCommandIndex + 1); } template -- cgit v1.1