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.
This commit is contained in:
Dan Gohman
2019-04-23 12:24:02 -07:00
parent e62607e552
commit 049c926e08

View File

@@ -1720,7 +1720,7 @@ __wasi_errno_t wasmtime_ssp_path_open(
bool write = bool write =
(rights_base & (__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_WRITE | (rights_base & (__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_WRITE |
__WASI_RIGHT_FD_ALLOCATE | __WASI_RIGHT_FD_ALLOCATE |
__WASI_RIGHT_PATH_FILESTAT_SET_SIZE)) != 0; __WASI_RIGHT_FD_FILESTAT_SET_SIZE)) != 0;
int noflags = write ? read ? O_RDWR : O_WRONLY : O_RDONLY; int noflags = write ? read ? O_RDWR : O_WRONLY : O_RDONLY;
// Which rights are needed on the directory file descriptor. // Which rights are needed on the directory file descriptor.
@@ -1738,7 +1738,7 @@ __wasi_errno_t wasmtime_ssp_path_open(
noflags |= O_EXCL; noflags |= O_EXCL;
if ((oflags & __WASI_O_TRUNC) != 0) { if ((oflags & __WASI_O_TRUNC) != 0) {
noflags |= O_TRUNC; noflags |= O_TRUNC;
needed_inheriting |= __WASI_RIGHT_PATH_FILESTAT_SET_SIZE; needed_base |= __WASI_RIGHT_PATH_FILESTAT_SET_SIZE;
} }
// Convert file descriptor flags. // Convert file descriptor flags.