[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 12 02:35:54 PST 2025
================
@@ -235,6 +252,12 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() {
Expected<StringRef> StrTabOrErr = getDynamicStrTab(Elf);
if (StrTabOrErr) {
const char *Data = StrTabOrErr->data();
+ if (Dyn.getVal() >= StringTableSize) {
+ reportWarning("invalid string table offset", Obj.getFileName());
----------------
jh7370 wrote:
`std::format` is C++20 and LLVM currently uses C++17, so that's not an option. There are various options, but LLVM already has plenty of good mechanisms for formatting things. In particular, the `Twine` class can be used to convert a number to a string and provides efficient concatenation with other `Twine` instances. There are also functions like `utohexstr` to make a `Twine` that is the hex form of a value, if you want to use that. An example of putting this all together is something like https://github.com/llvm/llvm-project/blob/37f36cbffb890a0c144211dec0c3589bd17f2a36/llvm/tools/llvm-objdump/llvm-objdump.cpp#L1265.
https://github.com/llvm/llvm-project/pull/125679
More information about the llvm-commits
mailing list