Fix rights check for fd_pread and fd_pwrite

This commit fixes rights check for `fd_pread` and `fd_pwrite` to be
conformant with the WASI spec. In the spec, it is clearly stated that
the right to invoke `__wasi_fd_pread()` requires a combination of
`__WASI_RIGHT_FD_READ` with `__WASI_RIGHT_FD_SEEK`, and similarly for
`__wasi_fd_pwrite()` the combination is `__WASI_RIGHT_FD_WRITE` with
`__WASI_RIGHT_FD_SEEK`. Relevant link to the spec: [__wasi_rights_t].

[__wasi_rights_t]: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs/wasi_unstable_preview1.md#__wasi_rights_t-uint64_t-bitfield
This commit is contained in:
Jakub Konka
2019-11-15 20:06:44 +01:00
committed by Jakub Konka
parent d4fd229e5e
commit 3d5b55c095
2 changed files with 3 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ unsafe fn test_file_pread_pwrite(dir_fd: wasi_unstable::Fd) {
0, 0,
"file", "file",
wasi_unstable::O_CREAT, wasi_unstable::O_CREAT,
wasi_unstable::RIGHT_FD_READ | wasi_unstable::RIGHT_FD_WRITE, wasi_unstable::RIGHT_FD_READ | wasi_unstable::RIGHT_FD_SEEK | wasi_unstable::RIGHT_FD_WRITE,
0, 0,
0, 0,
&mut file_fd, &mut file_fd,

View File

@@ -61,7 +61,7 @@ pub(crate) unsafe fn fd_pread(
let fd = wasi_ctx let fd = wasi_ctx
.get_fd_entry(fd)? .get_fd_entry(fd)?
.as_descriptor(wasi::__WASI_RIGHT_FD_READ, 0)? .as_descriptor(wasi::__WASI_RIGHT_FD_READ | wasi::__WASI_RIGHT_FD_SEEK, 0)?
.as_file()?; .as_file()?;
let iovs = dec_iovec_slice(memory, iovs_ptr, iovs_len)?; let iovs = dec_iovec_slice(memory, iovs_ptr, iovs_len)?;
@@ -110,7 +110,7 @@ pub(crate) unsafe fn fd_pwrite(
let fd = wasi_ctx let fd = wasi_ctx
.get_fd_entry(fd)? .get_fd_entry(fd)?
.as_descriptor(wasi::__WASI_RIGHT_FD_WRITE, 0)? .as_descriptor(wasi::__WASI_RIGHT_FD_WRITE | wasi::__WASI_RIGHT_FD_SEEK, 0)?
.as_file()?; .as_file()?;
let iovs = dec_ciovec_slice(memory, iovs_ptr, iovs_len)?; let iovs = dec_ciovec_slice(memory, iovs_ptr, iovs_len)?;