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

elf: parse shdr_relocs even if binary type is not ET_REL #118

Merged
merged 2 commits into from
Feb 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions src/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,16 @@ if_sylvan! {
dynsyms = Symtab::parse(bytes, dyn_info.symtab, num_syms, ctx)?;
}

// iterate through shdrs again iff we're an ET_REL
let shdr_relocs = {
let mut relocs = vec![];
if header.e_type == header::ET_REL {
for (idx, section) in section_headers.iter().enumerate() {
if section.sh_type == section_header::SHT_REL {
section.check_size(bytes.len())?;
let sh_relocs = RelocSection::parse(bytes, section.sh_offset as usize, section.sh_size as usize, false, ctx)?;
relocs.push((idx, sh_relocs));
}
if section.sh_type == section_header::SHT_RELA {
section.check_size(bytes.len())?;
let sh_relocs = RelocSection::parse(bytes, section.sh_offset as usize, section.sh_size as usize, true, ctx)?;
relocs.push((idx, sh_relocs));
}
}
let mut shdr_relocs = vec![];
for (idx, section) in section_headers.iter().enumerate() {
let is_rela = section.sh_type == section_header::SHT_RELA;
if is_rela || section.sh_type == section_header::SHT_REL {
section.check_size(bytes.len())?;
let sh_relocs = RelocSection::parse(bytes, section.sh_offset as usize, section.sh_size as usize, is_rela, ctx)?;
shdr_relocs.push((idx, sh_relocs));
}
relocs
};
}

Ok(Elf {
header: header,
program_headers: program_headers,
Expand Down