[llvm] [llvm-objdump][ELF]Fix crash when reading strings from .dynstr (PR #125679)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 01:54:25 PST 2025


================
@@ -221,6 +221,28 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() {
   std::string TagFmt = "  %-" + std::to_string(MaxLen) + "s ";
 
   outs() << "\nDynamic Section:\n";
+  typename ELFT::Xword StringTableSize{0};
+  for (const typename ELFT::Shdr &Sec : cantFail(Elf.sections())) {
+    if (Sec.sh_type == ELF::SHT_DYNSYM) {
+      Expected<const typename ELFT::Shdr *> StringTableSecOrError =
+          getSection<ELFT>(cantFail(Elf.sections()), Sec.sh_link);
+      if (!StringTableSecOrError) {
+        consumeError(StringTableSecOrError.takeError());
+        break;
+      }
+      StringTableSize = StringTableSize < (*StringTableSecOrError)->sh_size
+                            ? (*StringTableSecOrError)->sh_size
+                            : StringTableSize;
+    }
+  }
+  for (const typename ELFT::Dyn &Dyn : DynamicEntries) {
+    if (Dyn.d_tag == ELF::DT_STRSZ) {
+      StringTableSize =
+          StringTableSize < Dyn.getVal() ? Dyn.getVal() : StringTableSize;
----------------
jh7370 wrote:

As above, I think the point is moot now, since this code should disappear once we've fixed `getDynamicStrTab`.

https://github.com/llvm/llvm-project/pull/125679


More information about the llvm-commits mailing list