Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always flush when writing, even if we get invalid pointers #731

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/wasi/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) fn get_wasi_state(ctx: &Ctx) -> &mut WasiState {
unsafe { state::get_wasi_state(&mut *(ctx as *const Ctx as *mut Ctx)) }
}

fn write_bytes<T: Write>(
fn write_bytes_inner<T: Write>(
mut write_loc: T,
memory: &Memory,
iovs_arr_cell: &[Cell<__wasi_ciovec_t>],
Expand All @@ -44,19 +44,25 @@ fn write_bytes<T: Write>(
let iov_inner = iov.get();
let bytes = iov_inner.buf.deref(memory, 0, iov_inner.buf_len)?;
write_loc
.write(&bytes.iter().map(|b_cell| b_cell.get()).collect::<Vec<u8>>())
.map_err(|_| {
write_loc.flush();
__WASI_EIO
})?;
.write_all(&bytes.iter().map(|b_cell| b_cell.get()).collect::<Vec<u8>>())
.map_err(|_| __WASI_EIO)?;

// TODO: handle failure more accurately
bytes_written += iov_inner.buf_len;
}
write_loc.flush();
Ok(bytes_written)
}

fn write_bytes<T: Write>(
mut write_loc: T,
memory: &Memory,
iovs_arr_cell: &[Cell<__wasi_ciovec_t>],
) -> Result<u32, __wasi_errno_t> {
let result = write_bytes_inner(&mut write_loc, memory, iovs_arr_cell);
write_loc.flush();
result
}

fn read_bytes<T: Read>(
mut reader: T,
memory: &Memory,
Expand Down