Fix CI (#33139)
* programs/sbf: fix invalid_reference_casting errors in tests * programs/sbf: enable dev-context-only-utils on solana-sdk * programs/sbf: switch to clippy::arithmetic_side_effects * solana-program: fix formatting
This commit is contained in:
parent
3a91d3cc6a
commit
25d3db0c18
|
@ -5753,6 +5753,7 @@ dependencies = [
|
|||
name = "solana-sbf-rust-invoke"
|
||||
version = "1.17.0"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
"solana-program",
|
||||
"solana-sbf-rust-invoked",
|
||||
"solana-sbf-rust-realloc",
|
||||
|
|
|
@ -22,6 +22,7 @@ net2 = "0.2.37"
|
|||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
rand = "0.8"
|
||||
rustversion = "1.0.14"
|
||||
serde = "1.0.112"
|
||||
serde_json = "1.0.56"
|
||||
solana_rbpf = "=0.6.0"
|
||||
|
@ -101,6 +102,7 @@ solana_rbpf = { workspace = true }
|
|||
|
||||
[dev-dependencies]
|
||||
solana-ledger = { workspace = true }
|
||||
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
|
||||
|
||||
[[bench]]
|
||||
name = "bpf_loader"
|
||||
|
|
|
@ -14,6 +14,7 @@ default = ["program"]
|
|||
program = []
|
||||
|
||||
[dependencies]
|
||||
rustversion = { workspace = true }
|
||||
solana-program = { workspace = true }
|
||||
solana-sbf-rust-invoked = { workspace = true }
|
||||
solana-sbf-rust-realloc = { workspace = true }
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
//! Example Rust-based SBF program that issues a cross-program-invocation
|
||||
|
||||
pub mod instructions;
|
||||
pub mod processor;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#![cfg(feature = "program")]
|
||||
#![allow(unreachable_code)]
|
||||
#![allow(clippy::integer_arithmetic)]
|
||||
#![allow(clippy::arithmetic_side_effects)]
|
||||
|
||||
use {
|
||||
crate::instructions::*,
|
||||
|
@ -797,9 +797,10 @@ fn process_instruction(
|
|||
// AccountDataSizeChanged
|
||||
let serialized_len_ptr =
|
||||
unsafe { account.data.borrow_mut().as_mut_ptr().offset(-8) as *mut u64 };
|
||||
|
||||
unsafe {
|
||||
std::ptr::write(
|
||||
&account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
|
||||
overwrite_account_data(
|
||||
account,
|
||||
Rc::from_raw(((rc_box_addr as usize) + mem::size_of::<usize>() * 2) as *mut _),
|
||||
);
|
||||
}
|
||||
|
@ -836,10 +837,7 @@ fn process_instruction(
|
|||
// global_deallocator.dealloc(rc_box_addr) which is invalid and
|
||||
// happens to write a poison value into the account.
|
||||
unsafe {
|
||||
std::ptr::write(
|
||||
&account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
|
||||
Rc::new(RefCell::new(&mut [])),
|
||||
);
|
||||
overwrite_account_data(account, Rc::new(RefCell::new(&mut [])));
|
||||
}
|
||||
}
|
||||
TEST_FORBID_LEN_UPDATE_AFTER_OWNERSHIP_CHANGE => {
|
||||
|
@ -886,8 +884,8 @@ fn process_instruction(
|
|||
// allows us to test having CallerAccount::ref_to_len_in_vm in an
|
||||
// account region.
|
||||
unsafe {
|
||||
std::ptr::write(
|
||||
&account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
|
||||
overwrite_account_data(
|
||||
account,
|
||||
Rc::from_raw(((rc_box_addr as usize) + mem::size_of::<usize>() * 2) as *mut _),
|
||||
);
|
||||
}
|
||||
|
@ -920,10 +918,7 @@ fn process_instruction(
|
|||
// global_deallocator.dealloc(rc_box_addr) which is invalid and
|
||||
// happens to write a poison value into the account.
|
||||
unsafe {
|
||||
std::ptr::write(
|
||||
&account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
|
||||
Rc::new(RefCell::new(&mut [])),
|
||||
);
|
||||
overwrite_account_data(account, Rc::new(RefCell::new(&mut [])));
|
||||
}
|
||||
}
|
||||
TEST_ALLOW_WRITE_AFTER_OWNERSHIP_CHANGE_TO_CALLER => {
|
||||
|
@ -1133,9 +1128,13 @@ fn process_instruction(
|
|||
let account = &accounts[ARGUMENT_INDEX];
|
||||
let key = *account.key;
|
||||
let key = &key as *const _ as usize;
|
||||
#[rustversion::attr(since(1.72), allow(invalid_reference_casting))]
|
||||
fn overwrite_account_key(account: &AccountInfo, key: *const Pubkey) {
|
||||
unsafe {
|
||||
*mem::transmute::<_, *mut *const Pubkey>(&account.key) = key as *const Pubkey;
|
||||
*mem::transmute::<_, *mut *const Pubkey>(&account.key) = key;
|
||||
}
|
||||
}
|
||||
overwrite_account_key(account, key as *const Pubkey);
|
||||
let callee_program_id = accounts[CALLEE_PROGRAM_INDEX].key;
|
||||
|
||||
invoke(
|
||||
|
@ -1179,9 +1178,13 @@ fn process_instruction(
|
|||
const CALLEE_PROGRAM_INDEX: usize = 2;
|
||||
let account = &accounts[ARGUMENT_INDEX];
|
||||
let owner = account.owner as *const _ as usize + 1;
|
||||
#[rustversion::attr(since(1.72), allow(invalid_reference_casting))]
|
||||
fn overwrite_account_owner(account: &AccountInfo, owner: *const Pubkey) {
|
||||
unsafe {
|
||||
*mem::transmute::<_, *mut *const Pubkey>(&account.owner) = owner as *const Pubkey;
|
||||
*mem::transmute::<_, *mut *const Pubkey>(&account.owner) = owner;
|
||||
}
|
||||
}
|
||||
overwrite_account_owner(account, owner as *const Pubkey);
|
||||
let callee_program_id = accounts[CALLEE_PROGRAM_INDEX].key;
|
||||
|
||||
invoke(
|
||||
|
@ -1303,3 +1306,11 @@ struct RcBox<T> {
|
|||
weak: usize,
|
||||
value: T,
|
||||
}
|
||||
|
||||
#[rustversion::attr(since(1.72), allow(invalid_reference_casting))]
|
||||
unsafe fn overwrite_account_data(account: &AccountInfo, data: Rc<RefCell<&mut [u8]>>) {
|
||||
std::ptr::write(
|
||||
&account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Example Rust-based SBF realloc test program
|
||||
|
||||
#![cfg(feature = "program")]
|
||||
#![allow(clippy::integer_arithmetic)]
|
||||
#![allow(clippy::arithmetic_side_effects)]
|
||||
|
||||
extern crate solana_program;
|
||||
use {
|
||||
|
|
Loading…
Reference in New Issue