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 issue 370 #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
Loading