From 938bd86722dc9dc8c6cb89e03df3445fc2cba170 Mon Sep 17 00:00:00 2001 From: mjain-jump <150074777+mjain-jump@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:13:43 -0600 Subject: [PATCH] Refactor: reorder C-style syscall CPI check order (#3616) --- programs/bpf_loader/src/syscalls/cpi.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/programs/bpf_loader/src/syscalls/cpi.rs b/programs/bpf_loader/src/syscalls/cpi.rs index 7816cc473b905b..be252f911ec38d 100644 --- a/programs/bpf_loader/src/syscalls/cpi.rs +++ b/programs/bpf_loader/src/syscalls/cpi.rs @@ -639,11 +639,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC { invoke_context.get_check_aligned(), )?; - check_instruction_size( - ix_c.accounts_len as usize, - ix_c.data_len as usize, - invoke_context, - )?; let program_id = translate_type::( memory_mapping, ix_c.program_id_addr, @@ -655,28 +650,28 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC { ix_c.accounts_len, invoke_context.get_check_aligned(), )?; + let data = translate_slice::( + memory_mapping, + ix_c.data_addr, + ix_c.data_len, + invoke_context.get_check_aligned(), + )? + .to_vec(); + + check_instruction_size(ix_c.accounts_len as usize, data.len(), invoke_context)?; - let ix_data_len = ix_c.data_len; if invoke_context .get_feature_set() .is_active(&feature_set::loosen_cpi_size_restriction::id()) { consume_compute_meter( invoke_context, - (ix_data_len) + (data.len() as u64) .checked_div(invoke_context.get_compute_budget().cpi_bytes_per_unit) .unwrap_or(u64::MAX), )?; } - let data = translate_slice::( - memory_mapping, - ix_c.data_addr, - ix_data_len, - invoke_context.get_check_aligned(), - )? - .to_vec(); - let mut accounts = Vec::with_capacity(ix_c.accounts_len as usize); #[allow(clippy::needless_range_loop)] for account_index in 0..ix_c.accounts_len as usize {