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

Fix #5808: Handle possible dangling reference safely #5812

Merged
merged 4 commits into from
Jun 28, 2023

Conversation

matheus-consoli
Copy link
Contributor

Attempts to fix #5808.

Motivation

Handle Notify as a possible dangling reference to avoid Undefined Behavior.

Technically, this is not UB today because Notify uses an UnsafeCell internally, which prevents the problem with the pointer aliasing rules based on https://doc.rust-lang.org/stable/reference/behavior-considered-undefined.html.

Solution

Wrap the reference holder with a MaybeUninit.

@github-actions github-actions bot added the R-loom Run loom tests on this PR label Jun 22, 2023
@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync labels Jun 23, 2023
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR.

tokio-util/src/sync/cancellation_token.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/cancellation_token.rs Outdated Show resolved Hide resolved
@matheus-consoli matheus-consoli changed the title Fix #5080: Handle possible dangling reference safely Fix #5008: Handle possible dangling reference safely Jun 24, 2023
@matheus-consoli matheus-consoli changed the title Fix #5008: Handle possible dangling reference safely Fix #5808: Handle possible dangling reference safely Jun 24, 2023
@matheus-consoli matheus-consoli force-pushed the 5808-maybedangling branch 2 times, most recently from 9c61198 to eac9b92 Compare June 27, 2023 21:17
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Looks good to me.

@Darksonn Darksonn merged commit 1bfe778 into tokio-rs:master Jun 28, 2023
60 checks passed
@matheus-consoli matheus-consoli deleted the 5808-maybedangling branch June 28, 2023 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync R-loom Run loom tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WaitForCancellationFutureOwned should use MaybeUninit
2 participants