Skip to content

Commit

Permalink
INCOMPLETE: ban DWARF v5
Browse files Browse the repository at this point in the history
  • Loading branch information
indygreg committed May 6, 2023
1 parent deafad4 commit 6e14d0d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ clap = "4.2.5"
duct = "0.13.6"
flate2 = "1.0.26"
futures = "0.3.28"
gimli = "0.27.2"
goblin = "0.6.1"
hex = "0.4.3"
object = "0.31.0"
Expand Down
45 changes: 44 additions & 1 deletion src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use {
macho::{LoadCommandVariant, MachHeader, Nlist},
pe::{ImageNtHeaders, PeFile, PeFile32, PeFile64},
},
Endianness, FileKind, Object, SectionIndex, SymbolScope,
Endian, Endianness, FileKind, Object, SectionIndex, SymbolScope,
},
once_cell::sync::Lazy,
std::{
borrow::Cow,
collections::{BTreeSet, HashMap},
convert::TryInto,
io::Read,
Expand Down Expand Up @@ -990,6 +991,48 @@ fn validate_elf<'data, Elf: FileHeader<Endian = Endianness>>(
}
}

// Look at DWARF debug info.

let load_section = |id: gimli::SectionId| -> Result<Cow<[u8]>, gimli::Error> {
match sections.section_by_name(endian, id.name().as_ref()) {
Some((_, section)) => {
// TODO handle compression.
Ok(section
.data(endian, data)
.map(Cow::Borrowed)
.unwrap_or(Cow::Borrowed(&[][..])))
}
None => Ok(Cow::Borrowed(&[][..])),
}
};

let dwarf_cow = gimli::Dwarf::load(&load_section)?;

let borrow_section: &dyn for<'a> Fn(
&'a Cow<[u8]>,
) -> gimli::EndianSlice<'a, gimli::RunTimeEndian> = &|section| {
gimli::EndianSlice::new(
&*section,
if endian.is_big_endian() {
gimli::RunTimeEndian::Big
} else {
gimli::RunTimeEndian::Little
},
)
};

let dwarf = dwarf_cow.borrow(&borrow_section);

let mut iter = dwarf.units();
while let Some(header) = iter.next()? {
if header.version() > 4 {
context
.errors
.push(format!("{} has DWARF newer than version 4", path.display()));
break;
}
}

Ok(())
}

Expand Down

0 comments on commit 6e14d0d

Please sign in to comment.