From 286d265497a840f06e4ccb321c9bc81139d2e9a2 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 31 Jan 2025 21:56:21 -0500 Subject: Fix double free in CoreCallingConvention::callee_saved_registers Also added an assertion in the types unit test to catch it Fixes #6379 --- rust/src/calling_convention.rs | 1 - rust/tests/types.rs | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/rust/src/calling_convention.rs b/rust/src/calling_convention.rs index 929cc26b..9c1493e1 100644 --- a/rust/src/calling_convention.rs +++ b/rust/src/calling_convention.rs @@ -574,7 +574,6 @@ impl CallingConvention for CoreCallingConvention { unsafe { let mut count = 0; let regs_ptr = BNGetCalleeSavedRegisters(self.handle, &mut count); - BNFreeRegisterList(regs_ptr); let regs: Vec = std::slice::from_raw_parts(regs_ptr, count) .iter() .copied() diff --git a/rust/tests/types.rs b/rust/tests/types.rs index f745de0c..98530dc6 100644 --- a/rust/tests/types.rs +++ b/rust/tests/types.rs @@ -1,4 +1,6 @@ +use binaryninja::confidence::Conf; use binaryninja::headless::Session; +use binaryninja::platform::Platform; use binaryninja::types::{MemberAccess, MemberScope, StructureBuilder, StructureMember, Type}; use rstest::*; @@ -12,6 +14,14 @@ fn session() -> Session { fn test_type_to_string(_session: &Session) { let test_type = Type::int(4, true); assert_eq!(test_type.to_string(), "int32_t".to_string()); + + let platform = Platform::by_name("x86").expect("Failed to get platform"); + let calling_conv = platform + .get_default_calling_convention() + .expect("Failed to get calling convention"); + let test_fn_type = + Type::function_with_opts(&test_type, &[], false, calling_conv, Conf::new(0, 0)); + assert_eq!(test_fn_type.to_string(), "int32_t()"); } #[rstest] -- cgit v1.3.1