Skip to content

Commit 1973b85

Browse files
committed
Fix function type construction leaking in Rust API
1 parent 2c79a04 commit 1973b85

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl DebugInfoBuilder {
581581
for function in self.functions() {
582582
// let calling_convention: Option<Ref<CallingConvention<CoreArchitecture>>> = None;
583583

584-
debug_info.add_function(DebugFunctionInfo::new(
584+
debug_info.add_function(&DebugFunctionInfo::new(
585585
function.full_name.clone(),
586586
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
587587
function.raw_name.clone(),

plugins/idb_import/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn parse_id0_section_info(
269269
if bnty.is_none() {
270270
error!("Unable to convert the function type at {addr:#x}",)
271271
}
272-
if !debug_info.add_function(DebugFunctionInfo::new(
272+
if !debug_info.add_function(&DebugFunctionInfo::new(
273273
None,
274274
None,
275275
label.map(str::to_string),

plugins/pdb-ng/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
261261
address, &name.raw_name, type_
262262
)
263263
});
264-
self.debug_info.add_function(DebugFunctionInfo::new(
264+
self.debug_info.add_function(&DebugFunctionInfo::new(
265265
Some(name.short_name.unwrap_or(name.raw_name.clone())),
266266
Some(name.full_name.unwrap_or(name.raw_name.clone())),
267267
Some(name.raw_name),

rust/src/debuginfo.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,16 +770,25 @@ impl DebugInfo {
770770
}
771771

772772
/// Adds a function scoped under the current parser's name to the debug info
773-
pub fn add_function(&self, new_func: DebugFunctionInfo) -> bool {
774-
let short_name_bytes = new_func.short_name.map(|name| name.into_bytes_with_nul());
773+
pub fn add_function(&self, new_func: &DebugFunctionInfo) -> bool {
774+
let short_name_bytes = new_func
775+
.short_name
776+
.as_ref()
777+
.map(|name| name.into_bytes_with_nul());
775778
let short_name = short_name_bytes
776779
.as_ref()
777780
.map_or(std::ptr::null_mut() as *mut _, |name| name.as_ptr() as _);
778-
let full_name_bytes = new_func.full_name.map(|name| name.into_bytes_with_nul());
781+
let full_name_bytes = new_func
782+
.full_name
783+
.as_ref()
784+
.map(|name| name.into_bytes_with_nul());
779785
let full_name = full_name_bytes
780786
.as_ref()
781787
.map_or(std::ptr::null_mut() as *mut _, |name| name.as_ptr() as _);
782-
let raw_name_bytes = new_func.raw_name.map(|name| name.into_bytes_with_nul());
788+
let raw_name_bytes = new_func
789+
.raw_name
790+
.as_ref()
791+
.map(|name| name.into_bytes_with_nul());
783792
let raw_name = raw_name_bytes
784793
.as_ref()
785794
.map_or(std::ptr::null_mut() as *mut _, |name| name.as_ptr() as _);
@@ -816,11 +825,11 @@ impl DebugInfo {
816825
fullName: full_name,
817826
rawName: raw_name,
818827
address: new_func.address,
819-
type_: match new_func.type_ {
828+
type_: match &new_func.type_ {
820829
Some(type_) => type_.handle,
821830
_ => std::ptr::null_mut(),
822831
},
823-
platform: match new_func.platform {
832+
platform: match &new_func.platform {
824833
Some(platform) => platform.handle,
825834
_ => std::ptr::null_mut(),
826835
},

rust/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ impl Type {
771771
};
772772

773773
let result = unsafe {
774-
Self::ref_from_raw(BNNewTypeReference(BNCreateFunctionType(
774+
Self::ref_from_raw(BNCreateFunctionType(
775775
&mut owned_raw_return_type,
776776
&mut raw_calling_convention,
777777
raw_parameters.as_mut_ptr(),
@@ -785,7 +785,7 @@ impl Type {
785785
&mut return_regs,
786786
BNNameType::NoNameType,
787787
&mut pure,
788-
)))
788+
))
789789
};
790790

791791
for raw_param in raw_parameters {

rust/tests/debug_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl CustomDebugInfoParser for TestDebugInfoParser {
4545
vec![],
4646
vec![],
4747
);
48-
debug_info.add_function(test_func);
48+
debug_info.add_function(&test_func);
4949
true
5050
}
5151
}

0 commit comments

Comments
 (0)