Skip to content
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

Fix some BinaryInfo crashes #834

Merged
merged 2 commits into from Feb 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Next
BinaryInfo: ensure sh_name lies within file
This fixes segfault on ELFs with malformed section headers (sh_name),
such as one from eliben/pyelftools#367
  • Loading branch information
ksen-lin committed Feb 23, 2023
commit 32f325f4016e0090f76934320173581860f090be
9 changes: 8 additions & 1 deletion plugins/BinaryInfo/symbols.cpp
Expand Up @@ -174,7 +174,6 @@ the symbol is local; if uppercase, the symbol is global (external).

template <class M, class Size>
void collect_symbols(const void *p, Size size, std::vector<typename M::symbol> &symbols) {
Q_UNUSED(size)

using elf_addr = typename M::elf_addr;
using elf_header = typename M::elf_header;
Expand All @@ -200,6 +199,10 @@ void collect_symbols(const void *p, Size size, std::vector<typename M::symbol> &

// collect special section addresses
for (const elf_shdr *section = sections_begin; section != sections_end; ++section) {
if (section_strings + section->sh_name < (void *)base || section_strings + section->sh_name > (void *)(base + size)) {
continue;
}

if (strcmp(&section_strings[section->sh_name], ".plt") == 0) {
plt_address = section->sh_addr;
} else if (strcmp(&section_strings[section->sh_name], ".got") == 0) {
Expand All @@ -209,6 +212,10 @@ void collect_symbols(const void *p, Size size, std::vector<typename M::symbol> &

// print out relocated symbols for special sections
for (const elf_shdr *section = sections_begin; section != sections_end; ++section) {
if (section_strings + section->sh_name < (void *)base || section_strings + section->sh_name > (void *)(base + size)) {
continue;
}

elf_addr base_address = 0;
if (strcmp(&section_strings[section->sh_name], ".rela.plt") == 0) {
base_address = plt_address;
Expand Down