Skip to content

Contract implementation is unsafe and may trigger UB #3293

@celinval

Description

@celinval

Looking at the kani::internal::Pointer implementation for *mut T:

impl<'a, T> Pointer<'a> for *mut T {
type Inner = T;
unsafe fn decouple_lifetime(&self) -> &'a Self::Inner {
&**self as &'a T
}

This can trigger UB if the location pointed by *mut T does not contain a valid value of type T since it is converting it to a &T.
Converting *const T into &mut T and *mut T to &mut T is also unsafe, and may break aliasing rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Z-ContractsIssue related to code contracts[C] BugThis is a bug. Something isn't working.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions