Skip to content

Commit 992ba39

Browse files
ibhatt-jumptradingmjain-jump
authored andcommitted
cpi: zeroing out memory after shrinking acc data
1 parent df592ac commit 992ba39

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
23f340fd65d260dbb590f204dedfa9add60f46c0
1+
ac1cdc5030baa26590b2d7ef99845c2e70c49d51

src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,14 @@ VM_SYSCALL_CPI_UPDATE_CALLER_ACC_FUNC( fd_vm_t * vm,
556556
VM_SYSCALL_CPI_ACC_INFO_DATA( vm, caller_acc_info, caller_acc_data );
557557

558558
ulong const updated_data_len = fd_txn_account_get_data_len( callee_acc );
559-
if( !updated_data_len ) fd_memset( (void*)caller_acc_data, 0, caller_acc_data_len );
559+
560+
if( updated_data_len<caller_acc_data_len ) {
561+
/* We need to zero out memory that is no longer being used if the
562+
account shrunk in size during a CPI.
563+
https://github.com/anza-xyz/agave/blob/v2.3.1/programs/bpf_loader/src/syscalls/cpi.rs#L1403-L1407 */
564+
fd_memset( caller_acc_data + updated_data_len, 0, caller_acc_data_len - updated_data_len );
565+
}
566+
560567
ulong * ref_to_len = caller_account->ref_to_len_in_vm.translated;
561568
if( *ref_to_len != updated_data_len ) {
562569
ulong max_increase = (vm->direct_mapping && vm->is_deprecated) ? 0UL : MAX_PERMITTED_DATA_INCREASE;

0 commit comments

Comments
 (0)