[llvm] r238024 - Detect invalid section indexes when we first read them.
Rafael Espindola
rafael.espindola at gmail.com
Fri May 22 07:59:27 PDT 2015
Author: rafael
Date: Fri May 22 09:59:27 2015
New Revision: 238024
URL: http://llvm.org/viewvc/llvm-project?rev=238024&view=rev
Log:
Detect invalid section indexes when we first read them.
We still detect the same errors, but now we do it earlier.
Removed:
llvm/trunk/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName
Modified:
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/test/Object/macho-invalid.test
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=238024&r1=238023&r2=238024&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Fri May 22 09:59:27 2015
@@ -537,6 +537,8 @@ std::error_code MachOObjectFile::getSymb
} 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::getSectionFinalSegmentN
ArrayRef<char>
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<const section_base *>(Sections[Sec.d.a]);
return makeArrayRef(Base->sectname);
@@ -2155,8 +2156,7 @@ MachOObjectFile::getSectionRawName(DataR
ArrayRef<char>
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<const section_base *>(Sections[Sec.d.a]);
return makeArrayRef(Base->segname);
Removed: llvm/trunk/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName?rev=238023&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName (original) and llvm/trunk/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName (removed) differ
Modified: llvm/trunk/test/Object/macho-invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/macho-invalid.test?rev=238024&r1=238023&r2=238024&view=diff
==============================================================================
--- llvm/trunk/test/Object/macho-invalid.test (original)
+++ llvm/trunk/test/Object/macho-invalid.test Fri May 22 09:59:27 2015
@@ -25,11 +25,8 @@ RUN: | FileCheck -check-prefix BAD-
RUN: not llvm-objdump -t %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
RUN: | FileCheck -check-prefix NAME-PAST-EOF %s
-RUN: not llvm-objdump -t %p/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName 2>&1 \
-RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SEG-NAME %s
-
RUN: not llvm-nm %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
-RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SECT-NAME %s
+RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC %s
RUN: not llvm-objdump -t %p/Inputs/macho-invalid-getsection-index 2>&1 \
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-GETSECT %s
@@ -45,7 +42,6 @@ TOO-MANY-SECTS: Number of sections too l
BAD-SYMBOL: Requested symbol index is out of range
NAME-PAST-EOF: Symbol name entry points before beginning or past end of file
-INVALID-SECTION-IDX-SEG-NAME: getSectionRawFinalSegmentName: Invalid section index
-INVALID-SECTION-IDX-SECT-NAME: getSectionRawName: Invalid section index
+INVALID-SECTION-IDX-SYMBOL-SEC: getSymbolSection: Invalid section index
INVALID-SECTION-IDX-GETSECT: getSection: Invalid section index
INVALID-SECTION-IDX-GETSECT64: getSection64: Invalid section index
More information about the llvm-commits
mailing list