From 3d5b55c0950083e38bff2da55d07b74cfa1639fd Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 15 Nov 2019 20:06:44 +0100 Subject: [PATCH] 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 --- crates/test-programs/wasi-tests/src/bin/file_pread_pwrite.rs | 2 +- crates/wasi-common/src/hostcalls_impl/fs.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/test-programs/wasi-tests/src/bin/file_pread_pwrite.rs b/crates/test-programs/wasi-tests/src/bin/file_pread_pwrite.rs index e7773fea72..b9e9924ed1 100644 --- a/crates/test-programs/wasi-tests/src/bin/file_pread_pwrite.rs +++ b/crates/test-programs/wasi-tests/src/bin/file_pread_pwrite.rs @@ -14,7 +14,7 @@ unsafe fn test_file_pread_pwrite(dir_fd: wasi_unstable::Fd) { 0, "file", 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, &mut file_fd, diff --git a/crates/wasi-common/src/hostcalls_impl/fs.rs b/crates/wasi-common/src/hostcalls_impl/fs.rs index ae2485be21..382e00c99d 100644 --- a/crates/wasi-common/src/hostcalls_impl/fs.rs +++ b/crates/wasi-common/src/hostcalls_impl/fs.rs @@ -61,7 +61,7 @@ pub(crate) unsafe fn fd_pread( let fd = wasi_ctx .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()?; let iovs = dec_iovec_slice(memory, iovs_ptr, iovs_len)?; @@ -110,7 +110,7 @@ pub(crate) unsafe fn fd_pwrite( let fd = wasi_ctx .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()?; let iovs = dec_ciovec_slice(memory, iovs_ptr, iovs_len)?;