-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[llvm-objdump][ELF]Fix crash when reading strings from .dynstr #125679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2cc5751
e8414fc
1acfb61
61a78c9
21560c7
f1e32bc
4181db5
a8107b3
6eeb6ee
7e569fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,16 +63,24 @@ static Expected<StringRef> getDynamicStrTab(const ELFFile<ELFT> &Elf) { | |
if (!DynamicEntriesOrError) | ||
return DynamicEntriesOrError.takeError(); | ||
|
||
typename ELFT::Xword StringTableSize{0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. llvm style prefers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I followed this. Do you have any suggestions on which style is the correct one to use here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I got error with this.
I have discussed this with @jh7370 here, I initially use
which is unnecessarily redundant, then I modified to
but @jh7370 recommended
|
||
const uint8_t *MappedAddr = nullptr; | ||
for (const typename ELFT::Dyn &Dyn : *DynamicEntriesOrError) { | ||
if (Dyn.d_tag == ELF::DT_STRTAB) { | ||
auto MappedAddrOrError = Elf.toMappedAddr(Dyn.getPtr()); | ||
if (!MappedAddrOrError) | ||
return MappedAddrOrError.takeError(); | ||
return StringRef(reinterpret_cast<const char *>(*MappedAddrOrError)); | ||
MappedAddr = *MappedAddrOrError; | ||
} | ||
if (Dyn.d_tag == ELF::DT_STRSZ) | ||
StringTableSize = Dyn.getVal(); | ||
} | ||
if (MappedAddr && StringTableSize) | ||
return StringRef(reinterpret_cast<const char *>(MappedAddr), | ||
StringTableSize); | ||
|
||
// If the dynamic segment is not present, we fall back on the sections. | ||
// If the dynamic segment is not present, or is missing the important tags, we | ||
// fall back on the sections. | ||
auto SectionsOrError = Elf.sections(); | ||
if (!SectionsOrError) | ||
return SectionsOrError.takeError(); | ||
|
@@ -221,6 +229,7 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() { | |
std::string TagFmt = " %-" + std::to_string(MaxLen) + "s "; | ||
|
||
outs() << "\nDynamic Section:\n"; | ||
|
||
for (const typename ELFT::Dyn &Dyn : DynamicEntries) { | ||
if (Dyn.d_tag == ELF::DT_NULL) | ||
continue; | ||
|
@@ -235,6 +244,14 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() { | |
Expected<StringRef> StrTabOrErr = getDynamicStrTab(Elf); | ||
if (StrTabOrErr) { | ||
const char *Data = StrTabOrErr->data(); | ||
if (Dyn.getVal() >= StrTabOrErr->size()) { | ||
reportWarning("invalid string table offset, string table size: 0x" + | ||
Twine::utohexstr(StrTabOrErr->size()), | ||
Obj.getFileName()); | ||
outs() << format(TagFmt.c_str(), Str.c_str()) | ||
<< format(Fmt, (uint64_t)Dyn.getVal()); | ||
continue; | ||
} | ||
outs() << format(TagFmt.c_str(), Str.c_str()) << Data + Dyn.getVal() | ||
<< "\n"; | ||
continue; | ||
|
Uh oh!
There was an error while loading. Please reload this page.