Skip to content

Commit

Permalink
programs/sbf: "fix" invalid_reference_casting lint (#34706)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrod authored Jan 9, 2024
1 parent a78b520 commit 896a531
Showing 1 changed file with 2 additions and 8 deletions.
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(())
}

0 comments on commit 896a531

Please sign in to comment.