Skip to content

Commit

Permalink
Only use the shstrtab if it has the correct type.
Browse files Browse the repository at this point in the history
This avoids continuing the logic if the section header table isn't
present (except for the contrived case where the random bytes happen to
be the correct section type).
  • Loading branch information
afranchuk committed Aug 30, 2024
1 parent 52f3946 commit 66ffdb1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/linux/module_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ fn section_header_with_name<'sc>(
name: &[u8],
module_memory: &mut ProcessMemory<'_>,
) -> Result<Option<&'sc elf::SectionHeader>, Error> {
let strtab_section_header = section_headers.get(strtab_index).ok_or(Error::NoStrTab)?;
let strtab_section_header = section_headers
.get(strtab_index)
.and_then(|hdr| (hdr.sh_type == elf::section_header::SHT_STRTAB).then_some(hdr))
.ok_or(Error::NoStrTab)?;

for header in section_headers {
let sh_name = header.sh_name as u64;
if sh_name >= strtab_section_header.sh_size {
Expand Down

0 comments on commit 66ffdb1

Please sign in to comment.