-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Hello, thank you for your contribution in this projcet, I'm scanning unsoundness problem in rust project and I notice the following code.
pub struct ObjClosure {
pub obj: Obj,
pub function: Gc<ObjFunction>,
pub upvalues: NonNull<*mut ObjUpvalue>,
pub upvalue_count: u8,
}
impl ObjClosure{
pub fn upvalue_at_slot(&self, slot: usize) -> Option<NonNull<ObjUpvalue>> {
if self.upvalue_count == 0 {
return None;
}
unsafe {
let upvalues =
slice::from_raw_parts(self.upvalues.as_ptr(), self.upvalue_count as usize);
upvalues.get(slot).and_then(|upval| NonNull::new(*upval))
}
}
}
I am concerned that there may be a potential unsound problem here, since upvalues is a pub field and from_raw_parts is called without any checking, I am concerned that this may cause a potential UB (eg.null pointer), So I thought maybe marking upvalue_at_slot as unsafe would be a more appropriate choice?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels