Skip to content

Commit

Permalink
Follow eval-exec's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Jan 17, 2025
1 parent 98c41ab commit 007704d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions script/src/syscalls/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl<Mac: SupportMachine, DL: CellDataProvider + Send + Sync> Syscalls<Mac> for
let data = if length == 0 {
data.slice(offset..data_size)
} else {
// Both offset and length are <= u32::MAX, so offset.checked_add(length) will be always a Some.
let end = offset.checked_add(length).ok_or(VMError::MemOutOfBound)?;
if end > data_size {
machine.set_register(A0, Mac::REG::from_u8(SLICE_OUT_OF_BOUND));
Expand Down
9 changes: 5 additions & 4 deletions script/src/syscalls/exec_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ where
return Ok(true);
}
if length > 0 {
// Both offset and length are <= u32::MAX, so offset.checked_add(length) will be always a Some.
let end = offset.checked_add(length).ok_or(VMError::MemOutOfBound)?;
if end > full_length {
machine.set_register(A0, Mac::REG::from_u8(SLICE_OUT_OF_BOUND));
return Ok(true);
}
}

let argc = machine.registers()[A4].clone();
let argv = machine.registers()[A5].clone();
let argc = machine.registers()[A4].to_u64();
let argv = machine.registers()[A5].to_u64();
self.message_box
.lock()
.map_err(|e| VMError::Unexpected(e.to_string()))?
Expand All @@ -112,8 +113,8 @@ where
data_piece_id,
offset,
length,
argc: argc.to_u64(),
argv: argv.to_u64(),
argc: argc,
argv: argv,
},
));
Err(VMError::Yield)
Expand Down
1 change: 1 addition & 0 deletions script/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ where
)
}

/// Build syscall: exec. When script version >= V2, this exec implementation is used.
pub fn build_exec_v2(
&self,
snapshot2_context: Arc<Mutex<Snapshot2Context<DataPieceId, TxData<DL>>>>,
Expand Down

0 comments on commit 007704d

Please sign in to comment.