Skip to content

Commit

Permalink
Call parse_sections() and parse_dynamic() in SBPF v1 only.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Oct 16, 2024
1 parent d0fee43 commit eebc745
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl<C: ContextObject> Executable<C> {
aligned = AlignedMemory::<{ HOST_ALIGN }>::from_slice(bytes);
aligned.as_slice()
};
let elf = Elf64::parse(bytes)?;
let mut elf = Elf64::parse(bytes)?;
let enabled_sbpf_versions = loader.get_config().enabled_sbpf_versions.clone();
let sbpf_version = if *enabled_sbpf_versions.end() == SBPFVersion::V1 {
// Emulates a bug in the version dispatcher until we enable the first other version
Expand All @@ -403,6 +403,8 @@ impl<C: ContextObject> Executable<C> {
return Err(ElfError::UnsupportedSBPFVersion);
}
if sbpf_version == SBPFVersion::V1 {
elf.parse_sections()?;
elf.parse_dynamic()?;
Self::load_with_lenient_parser(&elf, bytes, loader)
} else {
Self::load_with_strict_parser(&elf, bytes, loader).map_err(|err| err.into())
Expand Down
11 changes: 5 additions & 6 deletions src/elf_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<'a> Elf64<'a> {
})
.transpose()?;

let mut parser = Self {
let parser = Self {
elf_bytes,
file_header,
program_header_table,
Expand All @@ -260,9 +260,6 @@ impl<'a> Elf64<'a> {
dynamic_symbol_names_section_header: None,
};

parser.parse_sections()?;
parser.parse_dynamic()?;

Ok(parser)
}

Expand Down Expand Up @@ -291,7 +288,8 @@ impl<'a> Elf64<'a> {
self.dynamic_relocations_table
}

fn parse_sections(&mut self) -> Result<(), ElfParserError> {
/// Parses the section header table.
pub fn parse_sections(&mut self) -> Result<(), ElfParserError> {
macro_rules! section_header_by_name {
($self:expr, $section_header:expr, $section_name:expr,
$($name:literal => $field:ident,)*) => {
Expand Down Expand Up @@ -326,7 +324,8 @@ impl<'a> Elf64<'a> {
Ok(())
}

fn parse_dynamic(&mut self) -> Result<(), ElfParserError> {
/// Parses the dynamic section.
pub fn parse_dynamic(&mut self) -> Result<(), ElfParserError> {
let mut dynamic_table: Option<&[Elf64Dyn]> = None;

// try to parse PT_DYNAMIC
Expand Down

0 comments on commit eebc745

Please sign in to comment.