From df599006c0a805dda992910722ac69a9adf794fc Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Fri, 26 Sep 2025 08:33:48 -0400 Subject: Fix Rust LowLevelILFunction owner function method LowLevelILFunction objects can be constructed without a owner function. BNGetLowLevelILOwnerFunction can return NULL and must be checked before creating a Function object. --- rust/src/low_level_il/function.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'rust/src') diff --git a/rust/src/low_level_il/function.rs b/rust/src/low_level_il/function.rs index 65c3536a..ca6508c9 100644 --- a/rust/src/low_level_il/function.rs +++ b/rust/src/low_level_il/function.rs @@ -88,8 +88,9 @@ where } pub(crate) fn arch(&self) -> CoreArchitecture { + // TODO: self.function() can return None under rare circumstances match self.arch { - None => self.function().arch(), + None => self.function().unwrap().arch(), Some(arch) => arch, } } @@ -167,10 +168,13 @@ where } } - pub fn function(&self) -> Ref { + pub fn function(&self) -> Option> { unsafe { let func = BNGetLowLevelILOwnerFunction(self.handle); - Function::ref_from_raw(func) + if func.is_null() { + return None; + } + Some(Function::ref_from_raw(func)) } } -- cgit v1.3.1