Skip to content

Commit 823ba5d

Browse files
committed
[llvm-objdump][ELF] Add Section size check. (#86612)
This change make the check of the section size to avoid crashing of llvm-objdump when processing misformated elf file. Signed-off-by: cabbaken <[email protected]>
1 parent 850852e commit 823ba5d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

llvm/tools/llvm-objdump/ELFDump.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() {
221221
std::string TagFmt = " %-" + std::to_string(MaxLen) + "s ";
222222

223223
outs() << "\nDynamic Section:\n";
224+
const auto StringTableSize =
225+
unwrapOrError(Elf.getSection(ELF::SHT_DYNAMIC), Obj.getFileName())
226+
->sh_size;
227+
224228
for (const typename ELFT::Dyn &Dyn : DynamicEntries) {
225229
if (Dyn.d_tag == ELF::DT_NULL)
226230
continue;
@@ -235,6 +239,11 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() {
235239
Expected<StringRef> StrTabOrErr = getDynamicStrTab(Elf);
236240
if (StrTabOrErr) {
237241
const char *Data = StrTabOrErr->data();
242+
if (Dyn.getVal() > StringTableSize) {
243+
reportWarning("Invalid string table offset for section .dynstr",
244+
Obj.getFileName());
245+
continue;
246+
}
238247
outs() << format(TagFmt.c_str(), Str.c_str()) << Data + Dyn.getVal()
239248
<< "\n";
240249
continue;

0 commit comments

Comments
 (0)