Skip to content

Commit

Permalink
Fix bugs in args_get and environ_get
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Konka committed Mar 20, 2020
1 parent 13bd7a5 commit 5e75830
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
) -> Result<()> {
trace!("args_get(argv_ptr={:?}, argv_buf={:?})", argv, argv_buf);

let mut argv_buf_offset: types::Size = 0;
for arg in &self.args {
let arg_bytes = arg.as_bytes_with_nul();
let elems = arg_bytes.len().try_into()?;
argv_buf.as_array(elems).copy_from_slice(arg_bytes)?;
argv.write(argv_buf)?;
argv = argv.add(1)?;
argv_buf_offset = argv_buf_offset.checked_add(elems).ok_or(Errno::Overflow)?;
argv_buf = argv_buf.add(argv_buf_offset)?;
argv_buf = argv_buf.add(elems)?;
}

Ok(())
Expand Down Expand Up @@ -60,17 +58,13 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
environ_buf
);

let mut environ_buf_offset: types::Size = 0;
for e in &self.env {
let environ_bytes = e.as_bytes_with_nul();
let elems = environ_bytes.len().try_into()?;
environ_buf.as_array(elems).copy_from_slice(environ_bytes)?;
environ.write(environ_buf)?;
environ = environ.add(1)?;
environ_buf_offset = environ_buf_offset
.checked_add(elems)
.ok_or(Errno::Overflow)?;
environ_buf = environ_buf.add(environ_buf_offset)?;
environ_buf = environ_buf.add(elems)?;
}

Ok(())
Expand Down

0 comments on commit 5e75830

Please sign in to comment.