summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-10 16:39:26 -0400
committerMason Reed <mason@vector35.com>2025-04-10 17:19:34 -0400
commit1973b852a1ffc2ea3e050d078a6f2b9933c199a1 (patch)
tree3f5fb2c328dd65ea2dff7b80de1b3e89d87d301e
parent2c79a0458cd5bc7af0264d18d8ca2fc1a7894228 (diff)
Fix function type construction leaking in Rust API
-rw-r--r--plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs2
-rw-r--r--plugins/idb_import/src/lib.rs2
-rw-r--r--plugins/pdb-ng/src/parser.rs2
-rw-r--r--rust/src/debuginfo.rs21
-rw-r--r--rust/src/types.rs4
-rw-r--r--rust/tests/debug_info.rs2
6 files changed, 21 insertions, 12 deletions
diff --git a/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs
index 672bdf68..604867f5 100644
--- a/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs
+++ b/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs
@@ -581,7 +581,7 @@ impl DebugInfoBuilder {
for function in self.functions() {
// let calling_convention: Option<Ref<CallingConvention<CoreArchitecture>>> = None;
- debug_info.add_function(DebugFunctionInfo::new(
+ debug_info.add_function(&DebugFunctionInfo::new(
function.full_name.clone(),
function.full_name.clone(), // TODO : This should eventually be changed, but the "full_name" should probably be the unsimplified version, and the "short_name" should be the simplified version...currently the symbols view shows the full version, so changing it here too makes it look bad in the UI
function.raw_name.clone(),
diff --git a/plugins/idb_import/src/lib.rs b/plugins/idb_import/src/lib.rs
index 70bbf07c..c554831d 100644
--- a/plugins/idb_import/src/lib.rs
+++ b/plugins/idb_import/src/lib.rs
@@ -269,7 +269,7 @@ fn parse_id0_section_info(
if bnty.is_none() {
error!("Unable to convert the function type at {addr:#x}",)
}
- if !debug_info.add_function(DebugFunctionInfo::new(
+ if !debug_info.add_function(&DebugFunctionInfo::new(
None,
None,
label.map(str::to_string),
diff --git a/plugins/pdb-ng/src/parser.rs b/plugins/pdb-ng/src/parser.rs
index 101b8868..783a8a2d 100644
--- a/plugins/pdb-ng/src/parser.rs
+++ b/plugins/pdb-ng/src/parser.rs
@@ -261,7 +261,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
address, &name.raw_name, type_
)
});
- self.debug_info.add_function(DebugFunctionInfo::new(
+ self.debug_info.add_function(&DebugFunctionInfo::new(
Some(name.short_name.unwrap_or(name.raw_name.clone())),
Some(name.full_name.unwrap_or(name.raw_name.clone())),
Some(name.raw_name),
diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs
index 34daeac1..1353f8b1 100644
--- a/rust/src/debuginfo.rs
+++ b/rust/src/debuginfo.rs
@@ -770,16 +770,25 @@ impl DebugInfo {
}
/// Adds a function scoped under the current parser's name to the debug info
- pub fn add_function(&self, new_func: DebugFunctionInfo) -> bool {
- let short_name_bytes = new_func.short_name.map(|name| name.into_bytes_with_nul());
+ pub fn add_function(&self, new_func: &DebugFunctionInfo) -> bool {
+ let short_name_bytes = new_func
+ .short_name
+ .as_ref()
+ .map(|name| name.into_bytes_with_nul());
let short_name = short_name_bytes
.as_ref()
.map_or(std::ptr::null_mut() as *mut _, |name| name.as_ptr() as _);
- let full_name_bytes = new_func.full_name.map(|name| name.into_bytes_with_nul());
+ let full_name_bytes = new_func
+ .full_name
+ .as_ref()
+ .map(|name| name.into_bytes_with_nul());
let full_name = full_name_bytes
.as_ref()
.map_or(std::ptr::null_mut() as *mut _, |name| name.as_ptr() as _);
- let raw_name_bytes = new_func.raw_name.map(|name| name.into_bytes_with_nul());
+ let raw_name_bytes = new_func
+ .raw_name
+ .as_ref()
+ .map(|name| name.into_bytes_with_nul());
let raw_name = raw_name_bytes
.as_ref()
.map_or(std::ptr::null_mut() as *mut _, |name| name.as_ptr() as _);
@@ -816,11 +825,11 @@ impl DebugInfo {
fullName: full_name,
rawName: raw_name,
address: new_func.address,
- type_: match new_func.type_ {
+ type_: match &new_func.type_ {
Some(type_) => type_.handle,
_ => std::ptr::null_mut(),
},
- platform: match new_func.platform {
+ platform: match &new_func.platform {
Some(platform) => platform.handle,
_ => std::ptr::null_mut(),
},
diff --git a/rust/src/types.rs b/rust/src/types.rs
index cb05a69d..9d1353bd 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -771,7 +771,7 @@ impl Type {
};
let result = unsafe {
- Self::ref_from_raw(BNNewTypeReference(BNCreateFunctionType(
+ Self::ref_from_raw(BNCreateFunctionType(
&mut owned_raw_return_type,
&mut raw_calling_convention,
raw_parameters.as_mut_ptr(),
@@ -785,7 +785,7 @@ impl Type {
&mut return_regs,
BNNameType::NoNameType,
&mut pure,
- )))
+ ))
};
for raw_param in raw_parameters {
diff --git a/rust/tests/debug_info.rs b/rust/tests/debug_info.rs
index b6a7ce7b..8b83363b 100644
--- a/rust/tests/debug_info.rs
+++ b/rust/tests/debug_info.rs
@@ -45,7 +45,7 @@ impl CustomDebugInfoParser for TestDebugInfoParser {
vec![],
vec![],
);
- debug_info.add_function(test_func);
+ debug_info.add_function(&test_func);
true
}
}