summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/InputFiles.cpp8
-rw-r--r--lld/test/ELF/invalid/Inputs/dynamic-section-sh_size.elfbin0 -> 482 bytes
-rw-r--r--lld/test/ELF/invalid/dynamic-section-size.s4
3 files changed, 8 insertions, 4 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 5b0ce109789..dda18aa8a4c 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -523,11 +523,11 @@ template <class ELFT> void SharedFile<ELFT>::parseSoName() {
if (!DynamicSec)
return;
- auto *Begin =
- reinterpret_cast<const Elf_Dyn *>(Obj.base() + DynamicSec->sh_offset);
- const Elf_Dyn *End = Begin + DynamicSec->sh_size / sizeof(Elf_Dyn);
- for (const Elf_Dyn &Dyn : make_range(Begin, End)) {
+ ArrayRef<Elf_Dyn> Arr =
+ check(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec),
+ getFilename(this) + ": getSectionContentsAsArray failed");
+ for (const Elf_Dyn &Dyn : Arr) {
if (Dyn.d_tag == DT_SONAME) {
uintX_t Val = Dyn.getVal();
if (Val >= this->StringTable.size())
diff --git a/lld/test/ELF/invalid/Inputs/dynamic-section-sh_size.elf b/lld/test/ELF/invalid/Inputs/dynamic-section-sh_size.elf
new file mode 100644
index 00000000000..ea35dba9517
--- /dev/null
+++ b/lld/test/ELF/invalid/Inputs/dynamic-section-sh_size.elf
Binary files differ
diff --git a/lld/test/ELF/invalid/dynamic-section-size.s b/lld/test/ELF/invalid/dynamic-section-size.s
new file mode 100644
index 00000000000..7d12904801e
--- /dev/null
+++ b/lld/test/ELF/invalid/dynamic-section-size.s
@@ -0,0 +1,4 @@
+## dynamic-section-sh_size.elf has incorrect sh_size of dynamic section.
+# RUN: not ld.lld %p/Inputs/dynamic-section-sh_size.elf -o %t2 2>&1 | \
+# RUN: FileCheck %s
+# CHECK: getSectionContentsAsArray failed: Invalid data was encountered while parsing the file
OpenPOWER on IntegriCloud