Browse Source

Handle set-size rights correctly when truncating a file.

If a path_open call is requesting __WASI_RIGHT_FD_FILESTAT_SET_SIZE,
interpret that as a request for write privleges. If it is requesting
O_TRUNC, require __WASI_RIGHT_PATH_FILESTAT_SET_SIZE, since this is
a path operation rather than a FD operation.
pull/502/head
Dan Gohman 6 years ago
committed by Jakub Konka
parent
commit
32da43f600
  1. 4
      src/hostcalls/fs.rs

4
src/hostcalls/fs.rs

@ -658,7 +658,7 @@ pub fn path_open(
& (host::__WASI_RIGHT_FD_DATASYNC & (host::__WASI_RIGHT_FD_DATASYNC
| host::__WASI_RIGHT_FD_WRITE | host::__WASI_RIGHT_FD_WRITE
| host::__WASI_RIGHT_FD_ALLOCATE | host::__WASI_RIGHT_FD_ALLOCATE
| host::__WASI_RIGHT_PATH_FILESTAT_SET_SIZE) | host::__WASI_RIGHT_FD_FILESTAT_SET_SIZE)
!= 0; != 0;
let mut nix_all_oflags = if read && write { let mut nix_all_oflags = if read && write {
@ -683,7 +683,7 @@ pub fn path_open(
needed_base |= host::__WASI_RIGHT_PATH_CREATE_FILE; needed_base |= host::__WASI_RIGHT_PATH_CREATE_FILE;
} }
if nix_all_oflags.contains(OFlag::O_TRUNC) { if nix_all_oflags.contains(OFlag::O_TRUNC) {
needed_inheriting |= host::__WASI_RIGHT_PATH_FILESTAT_SET_SIZE; needed_base |= host::__WASI_RIGHT_PATH_FILESTAT_SET_SIZE;
} }
// convert file descriptor flags // convert file descriptor flags

Loading…
Cancel
Save