summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2023-10-25 14:46:54 -0400
committerKyleMiles <krm504@nyu.edu>2023-10-25 14:46:54 -0400
commitfe9e37f6fc5a632bc022a3329b80c7ddd7afc499 (patch)
tree45e912feea0e484a4090f471eace8b20bd5fac7e
parent84c782175a002a0a62ba1b00234de6b89380c9fc (diff)
DWARF Import : Better detection and handling of malformed DWARF info; Resolves #4682
-rw-r--r--rust/README.md6
-rw-r--r--rust/examples/dwarf/dwarf_import/src/lib.rs18
2 files changed, 18 insertions, 6 deletions
diff --git a/rust/README.md b/rust/README.md
index a84fccf6..120af814 100644
--- a/rust/README.md
+++ b/rust/README.md
@@ -7,6 +7,12 @@
> :warning: This project runs on Rust version `stable-2022-12-15`
+## Contributing
+
+:warning: If you're thinking of contributing to the Rust API, we encourage you to join the #rust-api channel in our Slack: https://slack.binary.ninja, especially for large-effort PRs.
+Add a "Contributing" section to the Rust API readme
+
+
## Dependencies
Having BinaryNinja installed (and your license registered)
diff --git a/rust/examples/dwarf/dwarf_import/src/lib.rs b/rust/examples/dwarf/dwarf_import/src/lib.rs
index 7aab3775..4046e022 100644
--- a/rust/examples/dwarf/dwarf_import/src/lib.rs
+++ b/rust/examples/dwarf/dwarf_import/src/lib.rs
@@ -35,13 +35,13 @@ use dwarfreader::{
use gimli::{constants, DebuggingInformationEntry, Dwarf, DwarfFileType, Reader, SectionId, Unit};
-use log::{warn, LevelFilter};
+use log::{error, warn, LevelFilter};
use std::ffi::CString;
fn recover_names<R: Reader<Offset = usize>>(
debug_info_builder_context: &mut DebugInfoBuilderContext<R>,
progress: &dyn Fn(usize, usize) -> Result<(), ()>,
-) {
+) -> bool {
let mut iter = debug_info_builder_context.dwarf().units();
while let Ok(Some(header)) = iter.next() {
let unit = debug_info_builder_context.dwarf().unit(header).unwrap();
@@ -59,11 +59,14 @@ fn recover_names<R: Reader<Offset = usize>>(
debug_info_builder_context.total_die_count += 1;
if (*progress)(0, debug_info_builder_context.total_die_count).is_err() {
- return; // Parsing canceled
+ return false; // Parsing canceled
};
depth += delta_depth;
- assert!(depth >= 0);
+ if depth < 0 {
+ error!("DWARF information is seriously malformed. Aborting parsing.");
+ return false;
+ }
// TODO : Better module/component support
namespace_qualifiers.retain(|&(entry_depth, _)| entry_depth < depth);
@@ -180,6 +183,8 @@ fn recover_names<R: Reader<Offset = usize>>(
}
}
}
+
+ true
}
fn parse_unit<R: Reader<Offset = usize>>(
@@ -247,8 +252,9 @@ fn parse_dwarf(
// so we just do it up front
let mut debug_info_builder = DebugInfoBuilder::new();
if let Some(mut debug_info_builder_context) = DebugInfoBuilderContext::new(view, dwarf) {
- recover_names(&mut debug_info_builder_context, &progress);
- if debug_info_builder_context.total_die_count == 0 {
+ if !recover_names(&mut debug_info_builder_context, &progress)
+ || debug_info_builder_context.total_die_count == 0
+ {
return debug_info_builder;
}