Skip to content

Commit

Permalink
array: Fix UB in array_get_item (#8)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelwright235 authored Sep 20, 2024
1 parent ca07615 commit 215d73c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32, PlistError> {
Expand Down

0 comments on commit 215d73c

Please sign in to comment.