Skip to content
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

Two mut Refs at the same time #48

Closed
chpio opened this issue Oct 21, 2018 · 5 comments
Closed

Two mut Refs at the same time #48

chpio opened this issue Oct 21, 2018 · 5 comments

Comments

@chpio
Copy link

chpio commented Oct 21, 2018

as_owner_mut creates an additional mut ref to the stored ref, so we end up having two mutable ref at the same time. Why is this allowed? Changing data thru the mut ref should at least invalidate the stored ref (which is achievable by using the into_owned method -> mutating the owner -> making an OwningRefMut and mapping it again).

http://kimundi.github.io/owning-ref-rs/owning_ref/struct.OwningRefMut.html#method.as_owner_mut

@chpio chpio changed the title Mut and immut Ref allowed Two mut Refs at the same time Oct 21, 2018
@Storyyeller
Copy link
Contributor

into_owner takes Self, so you can't call it after calling as_owner_mut.

@chpio
Copy link
Author

chpio commented Oct 21, 2018

@Storyyeller Yeah? I was saying that it should be used instead of as_owner_mut.

@Storyyeller
Copy link
Contributor

I thought you were saying that you had found a soundness hole. Have you?

@chpio
Copy link
Author

chpio commented Oct 21, 2018

https://gist.github.com/rust-play/05def43b325e835d50cc97a1016c3c6f

edit: made code compile on rust stable. the hole is reproducible on nightly (rustc 1.31.0-nightly (424a749a0 2018-10-21)) and stable (rustc 1.29.2 (17a9dc751 2018-10-05))

@chpio
Copy link
Author

chpio commented Nov 23, 2018

*bump*

i guess a simple fix would be to remove as_owner_mut?

@chpio chpio closed this as completed Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants