Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit a310dd7

Browse files
authored
Fix - Uses std::mem::transmute and std::ptr::write in unsafe code in append_vec.rs (#32711)
Uses std::mem::transmute and std::ptr::write in unsafe code in append_vec.rs
1 parent 1844c42 commit a310dd7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

runtime/src/append_vec.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,13 @@ pub mod tests {
702702
}
703703

704704
impl AppendVecStoredAccountMeta<'_> {
705-
#[allow(clippy::cast_ref_to_mut)]
706705
fn set_data_len_unsafe(&self, new_data_len: u64) {
707706
// UNSAFE: cast away & (= const ref) to &mut to force to mutate append-only (=read-only) AppendVec
708707
unsafe {
709-
*(&self.meta.data_len as *const u64 as *mut u64) = new_data_len;
708+
std::ptr::write(
709+
std::mem::transmute::<*const u64, *mut u64>(&self.meta.data_len),
710+
new_data_len,
711+
);
710712
}
711713
}
712714

@@ -717,11 +719,13 @@ pub mod tests {
717719
executable_byte
718720
}
719721

720-
#[allow(clippy::cast_ref_to_mut)]
721722
fn set_executable_as_byte(&self, new_executable_byte: u8) {
722723
// UNSAFE: Force to interpret mmap-backed &bool as &u8 to write some crafted value;
723724
unsafe {
724-
*(&self.account_meta.executable as *const bool as *mut u8) = new_executable_byte;
725+
std::ptr::write(
726+
std::mem::transmute::<*const bool, *mut u8>(&self.account_meta.executable),
727+
new_executable_byte,
728+
);
725729
}
726730
}
727731
}

0 commit comments

Comments
 (0)