From e84305b4451f7cfcd3ffb842cc6584ff12c5c30f Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 7 Apr 2023 23:13:50 -0700 Subject: [PATCH] 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. --- crates/test-programs/wasi-tests/src/bin/symlink_create.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/test-programs/wasi-tests/src/bin/symlink_create.rs b/crates/test-programs/wasi-tests/src/bin/symlink_create.rs index 422da184cc..2553f34fcd 100644 --- a/crates/test-programs/wasi-tests/src/bin/symlink_create.rs +++ b/crates/test-programs/wasi-tests/src/bin/symlink_create.rs @@ -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); } }