From cc3f1db34c6395f6bcceebef357b723a3f25ea1d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 22 May 2015 14:59:27 +0000 Subject: [PATCH] Detect invalid section indexes when we first read them. We still detect the same errors, but now we do it earlier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238024 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 8 ++++---- ...d-section-index-getSectionRawFinalSegmentName | Bin 4536 -> 0 bytes test/Object/macho-invalid.test | 8 ++------ 3 files changed, 6 insertions(+), 10 deletions(-) delete mode 100644 test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index fc7b5f2863b..504b3172c9d 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/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); diff --git a/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName b/test/Object/Inputs/macho-invalid-section-index-getSectionRawFinalSegmentName deleted file mode 100644 index e3f658659226f8bee05714558525aa63377013bd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4536 zcmeHL!DsM*D7DrUM9{}fXVQ)&Y0XU9#D!+# z!d*qT{RH>jhzl1k{e$Ahr9V(aJZCavCLw|!Fc5fT=aW**! z$B_cl+IJd$2r%^4YvBT{cQi~PKF~=gXvLw{_3D;ewY6I_=&koXtamIdKpfqzU(F8x_vaVx74FPO+<~7i-a@{1gP;g`3#UQZ(|F&R zehqqKsKY$ok!NfGk6@fSBC?H<^F=sqICSP7g2(#-{+As_)&x8aS9PzZ%C4pCX4wX& zoq+QktFujaFLmYf$MI*c%0myGNyKn8G)8Cmg$OeSo5Fp$kMAEh_Q}J!)_%uN_<0ze z-su0R>G@72dpnDBxK?}jISlMKgAeb0KE(Op5F!_2_$KCwB@84CBn%`BBn%`BBn%`B zBn%`BBni;vVR)H6AZ^!K5*;hY*W4IPu|sIWke zjUi4mUM`8z$QYS)YB*@n4r4(>Uk~WYnsyq_O5Jz#nq%5dO-@xzw<>4ZbWmC+!~AHn zzn7*gzX6YA-xy-dg7gYvLm0VxBqpf<+j5r+k;Y??_2c*qaB0wxot<|@uCqxNAKssH z4WEo*#;6G+-A}xLPaN9}hDLclYP7{0!_5G9>c0jyT7T~*6QY(qr{<}WTXr`bWjmY7 zES0By$MZcUW_Cr?rdd;^^)krwRAWW?dNWtqs(F{1tFt*jfBl7JJ@=|!ZU(lxp^D0! g&R@0cYnQX@q64yZpJ!;VP!Vg-uUp!}pA~qWKkmAmumAu6 diff --git a/test/Object/macho-invalid.test b/test/Object/macho-invalid.test index ac4bbeb0da1..dae5c4eda7e 100644 --- a/test/Object/macho-invalid.test +++ b/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 -- 2.34.1