Skip to content

Arc::from_inner / Rc::from_inner should probably be marked unsafe #89740

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
sdroege opened this issue Oct 10, 2021 · 0 comments · Fixed by #89741
Closed

Arc::from_inner / Rc::from_inner should probably be marked unsafe #89740

sdroege opened this issue Oct 10, 2021 · 0 comments · Fixed by #89741

Comments

@sdroege
Copy link
Contributor

sdroege commented Oct 10, 2021

See

fn from_inner(ptr: NonNull<ArcInner<T>>) -> Self {
Self { ptr, phantom: PhantomData }
}

This can be called like

let dangling_arc = Arc::from_inner(NonNull::dangling());

without any unsafe code and results in an Arc to a dangling pointer, which will cause fun when trying to use it.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 20, 2021
…=Mark-Simulacrum

Mark `Arc::from_inner` / `Rc::from_inner` as unsafe

While it's an internal function, it is easy to create invalid Arc/Rcs to
a dangling pointer with it.

Fixes rust-lang#89740
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 20, 2021
…=Mark-Simulacrum

Mark `Arc::from_inner` / `Rc::from_inner` as unsafe

While it's an internal function, it is easy to create invalid Arc/Rcs to
a dangling pointer with it.

Fixes rust-lang#89740
@bors bors closed this as completed in 2e2c38e Nov 21, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant