-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OwningRefMut::as_owner and as_owner_mut are unsound #61
Comments
This was referenced Aug 3, 2022
This was referenced Sep 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No fancy Stacked Borrows stuff in this one, just normal memory unsafety. These methods of
OwningRefMut
:...are both unsound, because they can be used to access the owner object while the associated reference thinks it has unique access to it. In particular, it can be used to modify that data and invalidate the reference. (Doing so is straightforward with
as_owner_mut
, and is still possible withas_owner
with some interior mutability shenanigans.)Here is a simple test case for both methods. Clone the repo and run either
RUSTFLAGS="-Zsanitizer=address" cargo test as_owner_mut_is_unsound
RUSTFLAGS="-Zsanitizer=address" cargo test as_owner_is_unsound
and you should get a heap-use-after-free error.
This doesn't affect the non-Mut
OwningRef
;OwningRef::as_owner
is sound.The text was updated successfully, but these errors were encountered: