From: Kevin Enderby Date: Mon, 12 Oct 2015 22:04:54 +0000 (+0000) Subject: Fixed bugs in llvm-obdump while parsing Mach-O files from malformed archives X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=062054e5caa88d31ff93a21bf418d1e8d232cce3;p=oota-llvm.git Fixed bugs in llvm-obdump while parsing Mach-O files from malformed archives that caused aborts. This was because of the characters of the ‘Size’ field in the archive header did not contain decimal characters. rdar://22983603 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250117 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h index d7f46551827..5271dde5721 100644 --- a/include/llvm/Object/Archive.h +++ b/include/llvm/Object/Archive.h @@ -38,6 +38,7 @@ struct ArchiveMemberHeader { /// Members are not larger than 4GB. uint32_t getSize() const; + bool isSizeValid() const; sys::fs::perms getAccessMode() const; sys::TimeValue getLastModified() const; diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index 42fec39851d..b0e0881c789 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -50,6 +50,13 @@ uint32_t ArchiveMemberHeader::getSize() const { return Ret; } +bool ArchiveMemberHeader::isSizeValid() const { + uint32_t Ret; + if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, Ret)) + return false; + return true; +} + sys::fs::perms ArchiveMemberHeader::getAccessMode() const { unsigned Ret; if (StringRef(AccessMode, sizeof(AccessMode)).rtrim(" ").getAsInteger(8, Ret)) @@ -89,6 +96,11 @@ Archive::Child::Child(const Archive *Parent, const char *Start) uint64_t Size = sizeof(ArchiveMemberHeader); Data = StringRef(Start, Size); + // Check to make sure the size is valid. + const ArchiveMemberHeader *Header = + reinterpret_cast(Data.data()); + if (!Header->isSizeValid()) + return; if (!isThinMember()) { Size += getRawSize(); Data = StringRef(Start, Size); diff --git a/test/tools/llvm-objdump/X86/Inputs/malformed-machos/00000031.a b/test/tools/llvm-objdump/X86/Inputs/malformed-machos/00000031.a new file mode 100644 index 00000000000..b784d8163f5 Binary files /dev/null and b/test/tools/llvm-objdump/X86/Inputs/malformed-machos/00000031.a differ diff --git a/test/tools/llvm-objdump/X86/malformed-machos.test b/test/tools/llvm-objdump/X86/malformed-machos.test index a47e43443c5..c5778ed6f30 100644 --- a/test/tools/llvm-objdump/X86/malformed-machos.test +++ b/test/tools/llvm-objdump/X86/malformed-machos.test @@ -39,3 +39,9 @@ # RUN: | FileCheck -check-prefix=m0337 %s # m0337: subq $16, %rsp + +# RUN: llvm-objdump -macho -disassemble \ +# RUN: %p/Inputs/malformed-machos/00000031.a \ +# RUN: | FileCheck -check-prefix=0031a %s + +# 0031a: Archive