From 0d85d107478f2ebf889e33fd6f9657d8a6a99486 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 22 May 2015 14:59:27 +0000 Subject: Detect invalid section indexes when we first read them. We still detect the same errors, but now we do it earlier. llvm-svn: 238024 --- llvm/lib/Object/MachOObjectFile.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Object/MachOObjectFile.cpp') diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index fc7b5f2863b..504b3172c9d 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -537,6 +537,8 @@ std::error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb, } else { DataRefImpl DRI; DRI.d.a = index - 1; + if (DRI.d.a >= Sections.size()) + report_fatal_error("getSymbolSection: Invalid section index."); Res = section_iterator(SectionRef(DRI, this)); } @@ -2146,8 +2148,7 @@ MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec) const { ArrayRef MachOObjectFile::getSectionRawName(DataRefImpl Sec) const { - if (Sec.d.a >= Sections.size()) - report_fatal_error("getSectionRawName: Invalid section index"); + assert(Sec.d.a < Sections.size() && "Should have detected this earlier"); const section_base *Base = reinterpret_cast(Sections[Sec.d.a]); return makeArrayRef(Base->sectname); @@ -2155,8 +2156,7 @@ MachOObjectFile::getSectionRawName(DataRefImpl Sec) const { ArrayRef MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const { - if (Sec.d.a >= Sections.size()) - report_fatal_error("getSectionRawFinalSegmentName: Invalid section index"); + assert(Sec.d.a < Sections.size() && "Should have detected this earlier"); const section_base *Base = reinterpret_cast(Sections[Sec.d.a]); return makeArrayRef(Base->segname); -- cgit v1.2.3