From 6e4dae72fcf34d013fcd3ba7746b8534d09c71a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aurimas=20Bla=C5=BEulionis?= <0x60@pm.me> Date: Tue, 2 Jul 2024 17:08:28 +0000 Subject: [PATCH] Fix issue 370 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. --- src/elf/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/elf/mod.rs b/src/elf/mod.rs index 70c49146f..24fa78ff9 100644 --- a/src/elf/mod.rs +++ b/src/elf/mod.rs @@ -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; @@ -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 = §ion_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()) + } } };