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

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 10 00:30:34 PST 2025


================
@@ -221,6 +224,20 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() {
   std::string TagFmt = "  %-" + std::to_string(MaxLen) + "s ";
 
   outs() << "\nDynamic Section:\n";
+  auto StringTableSize = (typename ELFT::Xword)0;
+  for (const auto &Sec : cantFail(Elf.sections())) {
+    if (Sec.sh_type == ELF::SHT_STRTAB)
+      StringTableSize =
+          StringTableSize < Sec.sh_size ? Sec.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:

If it doesn't exist already somewhere, I think you may want a check that shows that the DT_STRSZ value makes sense, i.e. doesn't point past the end of the data. This could be a separate PR, but if you're concerned about invalid DT_NEEDED values, it makes equal sense to be concerned about invalid DT_STRSZ. NB: this could be checked already when you get the dynamic string table later - I haven't looked.

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


More information about the llvm-commits mailing list