From 215d73cfe1f3c3379c3b6a1db4c6e4a319fe13b4 Mon Sep 17 00:00:00 2001 From: Michael Wright <44947024+michaelwright235@users.noreply.github.com> Date: Fri, 20 Sep 2024 07:32:10 +0300 Subject: [PATCH] array: Fix UB in array_get_item (#8) Just like with `dict_get_item`, this one returns an item that's going to be dropped on the Rust side. This results in undefined behavior. To prevent this we set `false_drop` property to true. --- src/types/array.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/types/array.rs b/src/types/array.rs index 485f09d..11dc23f 100644 --- a/src/types/array.rs +++ b/src/types/array.rs @@ -24,7 +24,10 @@ impl Plist { return Err(PlistError::InvalidArg); } trace!("Getting array item"); - Ok(unsafe { unsafe_bindings::plist_array_get_item(self.plist_t, index) }.into()) + let mut plist: Plist = unsafe { unsafe_bindings::plist_array_get_item(self.plist_t, index) }.into(); + plist.false_drop = true; + + Ok(plist) } /// Gets the index of an array item pub fn array_get_item_index(&self) -> Result {