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: don't perform invalid reference cast #554

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions crates/mun_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,6 @@
Output: 'o + ReturnTypeReflection + Marshal<'o>,
'r: 'o,
{
// Safety: The output of `retry_impl` is guaranteed to only contain a shared
// reference.
let runtime = &*runtime;

loop {
self = match unsafe { self.retry_impl(runtime) } {
Ok(output) => return output,
Expand All @@ -687,15 +683,14 @@
///
/// # Safety
///
/// When calling this function, you have to guarantee that `runtime` is mutably
/// borrowed. The `Output` value can only contain a shared borrow of `runtime`.
unsafe fn retry_impl<'r, 'o, Output>(self, runtime: &'r Runtime) -> Result<Output, Self>
/// When calling this function, you have to guarantee that `runtime` can be dereferenced and is
/// valid for `'o`. The `Output` value can only contain a shared borrow of `runtime`.
unsafe fn retry_impl<'o, Output>(self, runtime: *mut Runtime) -> Result<Output, Self>

Check warning on line 688 in crates/mun_runtime/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_runtime/src/lib.rs#L688

Added line #L688 was not covered by tests
where
Output: 'o + ReturnTypeReflection + Marshal<'o>,
'r: 'o,
{
#[allow(invalid_reference_casting, invalid_reference_casting)]
let runtime = &mut *(runtime as *const Runtime as *mut Runtime);
// Safety: Guaranteed by the caller to be valid to dereference.
let runtime = &mut *runtime;

Check warning on line 693 in crates/mun_runtime/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_runtime/src/lib.rs#L692-L693

Added lines #L692 - L693 were not covered by tests

eprintln!("{}", self.msg);
while !runtime.update() {
Expand Down
Loading