Add a WASI test for a creating an absolute-path symlink. (#6166)

Wasmtime disallows guests from using `path_symlink` to create
absolute-path symlinks, as they could confuse other code into
accessing resources on the host that the guest otherwise doesn't
have access to.

This patch adds a test for this behavior.
This commit is contained in:
Dan Gohman
2023-04-07 23:13:50 -07:00
committed by GitHub
parent bada17beab
commit e84305b445

View File

@@ -62,6 +62,11 @@ unsafe fn create_symlink_to_directory(dir_fd: wasi::Fd) {
.expect("remove_directory on a directory should succeed");
}
unsafe fn create_symlink_to_root(dir_fd: wasi::Fd) {
// Create a symlink.
wasi::path_symlink("/", dir_fd, "symlink").expect_err("creating a symlink to an absolute path");
}
fn main() {
let mut args = env::args();
let prog = args.next().unwrap();
@@ -85,5 +90,6 @@ fn main() {
unsafe {
create_symlink_to_file(dir_fd);
create_symlink_to_directory(dir_fd);
create_symlink_to_root(dir_fd);
}
}