Skip to content

Commit

Permalink
Fix issue 370
Browse files Browse the repository at this point in the history
The issue gets triggered, because qemu/virsh generated elf dump contains strtab
at the end of the dump file. Meanwhile, dumps are large, and thus, it is
infeasible to provide the entire dump file to the parser. This PR relaxes the
requirements of the parser and returns default strtab, if the initial size
check fails.
  • Loading branch information
h33p committed Jul 2, 2024
1 parent 6177758 commit 6e4dae7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ if_sylvan! {
use crate::container::{Container, Ctx};
use alloc::vec::Vec;
use core::cmp;
use log::warn;

pub use header::Header;
pub use program_header::ProgramHeader;
Expand Down Expand Up @@ -286,12 +287,19 @@ if_sylvan! {
}

if section_idx >= section_headers.len() {
// FIXME: warn! here
warn!("strtab section idx {} is out of bounds ({})", section_idx, section_headers.len());
Ok(Strtab::default())
} else {
let shdr = &section_headers[section_idx];
shdr.check_size(bytes.len())?;
Strtab::parse(bytes, shdr.sh_offset as usize, shdr.sh_size as usize, 0x0)
// If size check fails, that means strtab is outside user supplied buffer. We
// can either hard-fail there, or return an empty strtab. The latter is less
// disturbing.
if shdr.check_size(bytes.len()).is_ok() {
Strtab::parse(bytes, shdr.sh_offset as usize, shdr.sh_size as usize, 0x0)
} else {
warn!("strtab section goes outside the provided buffer");
Ok(Strtab::default())
}
}
};

Expand Down

0 comments on commit 6e4dae7

Please sign in to comment.