From 1900b7c0804143832e1a81568287e3f4d230548f Mon Sep 17 00:00:00 2001 From: Jack May Date: Sun, 16 Aug 2020 23:11:52 -0700 Subject: [PATCH] fix region checks (#11651) (cherry picked from commit 768b386f0a1bcc01be05df3b4c5a8fdeee729d85) --- programs/bpf_loader/src/syscalls.rs | 4 ++-- sdk/src/pubkey.rs | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index 954b7128921b3f..2ae4d942db98c8 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -355,10 +355,10 @@ pub fn syscall_create_program_address( ) }) .collect::, EbpfError>>()?; - let program_id = translate_type!(Pubkey, program_id_addr, rw_regions)?; + let program_id = translate_type!(Pubkey, program_id_addr, ro_regions)?; let new_address = Pubkey::create_program_address(&seeds, program_id).map_err(SyscallError::BadSeeds)?; - let address = translate_slice_mut!(u8, address_addr, 32, ro_regions)?; + let address = translate_slice_mut!(u8, address_addr, 32, rw_regions)?; address.copy_from_slice(new_address.as_ref()); Ok(0) } diff --git a/sdk/src/pubkey.rs b/sdk/src/pubkey.rs index c6a69c4f8e880e..3807ea502c3501 100644 --- a/sdk/src/pubkey.rs +++ b/sdk/src/pubkey.rs @@ -139,16 +139,13 @@ impl Pubkey { address_bytes_addr: *const u8, ) -> u64; }; - let bytes = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, - ]; + let mut bytes = [0; 32]; let result = unsafe { sol_create_program_address( seeds as *const _ as *const u8, seeds.len() as u64, program_id as *const _ as *const u8, - &bytes as *const _ as *const u8, + &mut bytes as *mut _ as *mut u8, ) }; match result {