-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix soundness hole in join macros (#2649)
* fix soundness hole in join macros add a miri regression test update failing tests (join sizes increased due to fix) * fix `CI / cross test` by ignoring `join_size` and `try_join_size` tests on "non-64-bit pointer" targets (e.g. `i686-unknown-linux-gnu`) (this is the same fix that was also applied in PR #2447)
- Loading branch information
1 parent
521f2ae
commit 44dc9ef
Showing
3 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use futures::executor::block_on; | ||
use futures::future::Future; | ||
use std::task::Poll; | ||
|
||
/// This tests verifies (through miri) that self-referencing | ||
/// futures are not invalidated when joining them. | ||
#[test] | ||
fn futures_join_macro_self_referential() { | ||
block_on(async { futures::join!(yield_now(), trouble()) }); | ||
} | ||
|
||
async fn trouble() { | ||
let lucky_number = 42; | ||
let problematic_variable = &lucky_number; | ||
|
||
yield_now().await; | ||
|
||
// problematic dereference | ||
let _ = { *problematic_variable }; | ||
} | ||
|
||
fn yield_now() -> impl Future<Output = ()> { | ||
let mut yielded = false; | ||
std::future::poll_fn(move |cx| { | ||
if core::mem::replace(&mut yielded, true) { | ||
Poll::Ready(()) | ||
} else { | ||
cx.waker().wake_by_ref(); | ||
Poll::Pending | ||
} | ||
}) | ||
} |