Skip to content

Commit

Permalink
Support ELF with empty PT_DYNAMIC reference (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-auer authored and m4b committed Dec 3, 2019
1 parent ea3377a commit e5ff551
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/elf/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,14 @@ if_alloc! {
let offset = phdr.p_offset as usize;
let filesz = phdr.p_filesz as usize;
// Ensure offset and filesz are valid.
let bytes = bytes
.pread_with::<&[u8]>(offset, filesz)
.map_err(|_| crate::error::Error::Malformed(format!("Invalid PT_DYNAMIC size (offset {:#x}, filesz {:#x})",
offset, filesz)))?;
let bytes = if filesz > 0 {
bytes
.pread_with::<&[u8]>(offset, filesz)
.map_err(|_| crate::error::Error::Malformed(format!("Invalid PT_DYNAMIC size (offset {:#x}, filesz {:#x})",
offset, filesz)))?
} else {
&[]
};
let size = Dyn::size_with(&ctx);
let count = filesz / size;
let mut dyns = Vec::with_capacity(count);
Expand Down

0 comments on commit e5ff551

Please sign in to comment.