-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow opening directory with rights::fd_write
This commit changes `path_open` such that opening an existing directory with the `rights::fd_write` flag set returns an error `isdir`. This behavior is consistent with other runtimes. fixes #4766
- Loading branch information
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#[link(wasm_import_module = "wasi_snapshot_preview1")] | ||
extern "C" { | ||
pub fn path_open( | ||
fd: i32, | ||
dirflags: i32, | ||
path: i32, | ||
path_len: i32, | ||
oflags: i32, | ||
fs_rights_base: i64, | ||
fs_rights_inheriting: i64, | ||
fdflags: i32, | ||
result_fd: i32, | ||
) -> i32; | ||
} | ||
|
||
const ERRNO_ISDIR: i32 = 31; | ||
const RIGHTS_FD_WRITE: i64 = 64; | ||
|
||
fn main() { | ||
unsafe { | ||
let base_fd = 5; | ||
let path = "fyi/fs_open_dir_write.dir"; | ||
let errno = path_open( | ||
base_fd, | ||
0, | ||
path.as_ptr() as i32, | ||
path.as_bytes().len() as i32, | ||
0, | ||
RIGHTS_FD_WRITE, | ||
0, | ||
0, | ||
1024, | ||
); | ||
assert_eq!( | ||
errno, ERRNO_ISDIR, | ||
"opening a dir with rights::fd_write should fail" | ||
); | ||
} | ||
} |
Empty file.