summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp8
-rw-r--r--llvm/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentNamebin4536 -> 0 bytes
-rw-r--r--llvm/test/Object/macho-invalid.test8
3 files changed, 6 insertions, 10 deletions
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<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(DataRefImpl Sec) const {
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);
diff --git a/llvm/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName b/llvm/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName
deleted file mode 100644
index e3f65865922..00000000000
--- a/llvm/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName
+++ /dev/null
Binary files differ
diff --git a/llvm/test/Object/macho-invalid.test b/llvm/test/Object/macho-invalid.test
index ac4bbeb0da1..dae5c4eda7e 100644
--- a/llvm/test/Object/macho-invalid.test
+++ b/llvm/test/Object/macho-invalid.test
@@ -25,11 +25,8 @@ RUN: | FileCheck -check-prefix BAD-SYMBOL %s
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 large for size of load command
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
OpenPOWER on IntegriCloud