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

programs/sbf: "fix" invalid_reference_casting lint #34706

Merged
merged 1 commit into from
Jan 9, 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
10 changes: 2 additions & 8 deletions programs/sbf/rust/spoof1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ fn process_instruction(
let mut tmp_native_owner = [0u8; 32];
tmp_native_owner.copy_from_slice(accounts[0].owner.as_ref());

let owner_addr = accounts[0].owner as *const Pubkey;
unsafe {
std::ptr::write_volatile(owner_addr as *mut [u8; 32], fake_system.owner.to_bytes());
}
accounts[0].assign(fake_system.owner);

let system = &accounts[0];
let mut new_system = system.clone();
Expand All @@ -44,10 +41,7 @@ fn process_instruction(
msg!("swapped owner and data");
invoke(&ix, &[target.clone(), me.clone(), new_system])?;

let owner_addr = accounts[0].owner as *const Pubkey;
unsafe {
std::ptr::write_volatile(owner_addr as *mut [u8; 32], tmp_native_owner);
}
accounts[0].assign(&Pubkey::from(tmp_native_owner));

Ok(())
}