[ELF] Disallow out-of-range section group indices after D70146
authorFangrui Song <i@maskray.me>
Tue, 19 Nov 2019 17:47:17 +0000 (09:47 -0800)
committerFangrui Song <i@maskray.me>
Tue, 19 Nov 2019 17:49:45 +0000 (09:49 -0800)
Exposed by invalid/sht-group-wrong-section.test
http://45.33.8.238/win/2613/step_9.txt

lld/ELF/InputFiles.cpp

index 0026aeef58dbac3867d86810fdde11d7be2ef82a..7dc72361abd75b35d48e8bd37b8bc78d9eff4a0d 100644 (file)
@@ -621,6 +621,8 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
     InputSectionBase *head;
     InputSectionBase *prev = nullptr;
     for (uint32_t secIndex : entries.slice(1)) {
+      if (secIndex >= this->sections.size())
+        continue;
       InputSectionBase *s = this->sections[secIndex];
       if (!s || s == &InputSection::discarded)
         continue;