PropList array items should return NULL on OOB index access.

This commit is contained in:
2025-10-23 14:46:56 -04:00
parent 7bded0055f
commit 1a8d99b2c0
+13 -3
View File
@@ -666,10 +666,11 @@ pub mod ffi {
}
let plist = unsafe { &*plist };
if let Node::Array(ref items) = *plist.0.borrow() {
Box::leak(Box::new(items[index as usize].clone()))
} else {
ptr::null_mut()
if let Some(x) = items.get(index as usize) {
return Box::leak(Box::new(x.clone()));
}
}
ptr::null_mut()
}
#[unsafe(no_mangle)]
@@ -850,4 +851,13 @@ mod test {
unsafe { memory::ffi::wfree(desc.cast()); }
}
#[test]
fn oob_array_access_returns_null() {
// This is the original WMArray behavior. I don't like it, but a bunch
// of existing code relies on it.
let mut list = PropList::new(Node::Array(vec![PropList::new(Node::String(CString::from(c"hello"))),
PropList::new(Node::String(CString::from(c"world!")))]));
assert!(unsafe { ffi::WMGetFromPLArray(&mut list, 3) }.is_null());
}
}