Skip to content

Commit 0ad2143

Browse files
anarcheuzmjain-jump
authored andcommitted
flamenco: skip checks on next region if memset succeeded
1 parent 33ede17 commit 0ad2143

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/flamenco/vm/syscall/fd_vm_syscall_util.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ fd_vm_syscall_sol_memset( /**/ void * _vm,
803803
ulong bytes_in_cur_region = fd_ulong_sat_sub( vm->input_mem_regions[ region_idx ].region_sz, offset_in_cur_region );
804804

805805
/* Check that current region is writable */
806-
if( FD_UNLIKELY( !vm->input_mem_regions[ region_idx ].is_writable && sz ) ) {
806+
if( FD_UNLIKELY( !vm->input_mem_regions[ region_idx ].is_writable ) ) {
807807
FD_VM_ERR_FOR_LOG_EBPF( vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION );
808808
return FD_VM_SYSCALL_ERR_SEGFAULT;
809809
}
@@ -816,6 +816,10 @@ fd_vm_syscall_sol_memset( /**/ void * _vm,
816816
fd_memset( haddr, b, num_bytes_to_set );
817817
sz -= num_bytes_to_set;
818818

819+
if( !sz ) {
820+
break;
821+
}
822+
819823
/* If no more regions left, break. */
820824
if( ++region_idx==vm->input_mem_regions_cnt ) {
821825
break;
@@ -828,7 +832,7 @@ fd_vm_syscall_sol_memset( /**/ void * _vm,
828832

829833
/* If new region crosses into/out of account region, error out. */
830834
if( FD_UNLIKELY( vm->input_mem_regions[ region_idx ].is_acct_data !=
831-
vm->input_mem_regions[ region_idx-1UL ].is_acct_data && sz ) ) {
835+
vm->input_mem_regions[ region_idx-1UL ].is_acct_data ) ) {
832836
FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH );
833837
return FD_VM_SYSCALL_ERR_SEGFAULT;
834838
}

0 commit comments

Comments
 (0)