From bac8dfd91ccb637f9d04a91e33f6755e857e39e0 Mon Sep 17 00:00:00 2001 From: ibhatt-jumptrading Date: Wed, 31 Jul 2024 19:04:44 +0000 Subject: [PATCH] more pr comments --- src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c b/src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c index 65c37d5b94..144aae3bbb 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c @@ -384,7 +384,7 @@ TODO: error codes static int VM_SYSCALL_CPI_UPDATE_CALLER_ACC_FUNC( fd_vm_t * vm, VM_SYSCALL_CPI_ACC_INFO_T * caller_acc_info, - uchar FD_FN_UNUSED instr_acc_idx, + uchar instr_acc_idx, fd_pubkey_t const * pubkey ) { if( !FD_FEATURE_ACTIVE( vm->instr_ctx->slot_ctx, bpf_account_data_direct_mapping ) ) { @@ -457,20 +457,24 @@ VM_SYSCALL_CPI_UPDATE_CALLER_ACC_FUNC( fd_vm_t * vm, /* Make sure that the capacity of the borrowed account is sized up in case it was shrunk in the CPI. It needs to be sized up in order to fit within - the originally delinated regions when the account data was serialized. */ + the originally delinated regions when the account data was serialized. + https://github.com/anza-xyz/agave/blob/36323b6dcd3e29e4d6fe6d73d716a3f33927148b/programs/bpf_loader/src/syscalls/cpi.rs#L1311 */ VM_SYSCALL_CPI_ACC_INFO_METADATA( vm, caller_acc_info, caller_acc_metadata ); ulong region_idx = vm->acc_region_metas[ instr_acc_idx ].region_idx; uint original_len = vm->acc_region_metas[ instr_acc_idx ].has_data_region ? vm->input_mem_regions[ region_idx ].region_sz : 0U; - int zero_all_mapped_spare_capacity = 0; + uchar zero_all_mapped_spare_capacity = 0; /* This case can only be triggered if the original length is more than 0 */ if( callee_acc_rec->const_meta->dlen < original_len ) { ulong new_len = callee_acc_rec->const_meta->dlen; /* Allocate into the buffer to make sure that the original data len is still valid but don't change the dlen. Zero out the rest of the memory which is not used. */ - fd_instr_borrowed_account_modify( vm->instr_ctx, pubkey, original_len, &callee_acc_rec ); + err = fd_instr_borrowed_account_modify( vm->instr_ctx, pubkey, original_len, &callee_acc_rec ); + if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) { + return 1; + } callee_acc_rec->meta->dlen = new_len; zero_all_mapped_spare_capacity = 1; } @@ -493,7 +497,7 @@ VM_SYSCALL_CPI_UPDATE_CALLER_ACC_FUNC( fd_vm_t * vm, original data len + the max resizing limit (10KiB). Can't resize the account if the deprecated loader is being used */ ulong max_increase = vm->is_deprecated ? 0UL : 10240UL; - if( FD_UNLIKELY( post_len>fd_ulong_sat_add( original_len, max_increase ) ) ) { + if( FD_UNLIKELY( post_len>fd_ulong_sat_add( (ulong)original_len, max_increase ) ) ) { return FD_EXECUTOR_INSTR_ERR_INVALID_REALLOC; } /* There is additonal handling in the case where the account is larger