Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

wizer: Don't provide WASI by default (#11867)

Alex Crichton0ba595de6756
diff --git a/src/commands/wizer.rs b/src/commands/wizer.rs
index 47ee877eec..4d47bfa2b4 100644
--- a/src/commands/wizer.rs
+++ b/src/commands/wizer.rs
@@ -41,6 +41,13 @@ impl WizerCommand {
self.run.common.wasm.relaxed_simd_deterministic = Some(true);
}
+ // Don't provide any WASI imports by default to wizened components. The
+ // `run` command provides the "cli" world as a default so turn that off
+ // here if the command line flags don't otherwise say what to do.
+ if self.run.common.wasi.cli.is_none() {
+ self.run.common.wasi.cli = Some(false);
+ }
+
// Read the input wasm, possibly from stdin.
let mut wasm = Vec::new();
if self.input.to_str() == Some("-") {
diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs
index f623dedacb..e08d0074c2 100644
--- a/tests/all/cli_tests.rs
+++ b/tests/all/cli_tests.rs
@@ -2623,3 +2623,64 @@ fn big_table_in_pooling_allocator() -> Result<()> {
])?;
Ok(())
}
+
+fn wizen(args: &[&str], wat: &str) -> Result<Output> {
+ let mut cmd = get_wasmtime_command()?;
+ cmd.arg("wizer").args(args).arg("-");
+ cmd.stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .stderr(Stdio::piped());
+ let mut child = cmd.spawn()?;
+ let mut stdin = child.stdin.take().unwrap();
+ stdin.write_all(wat.as_bytes())?;
+ drop(stdin);
+
+ let output = child.wait_with_output()?;
+ if !output.status.success() {
+ println!(
+ "Failed to execute wasmtime wizer with: {cmd:?}\n{}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ }
+ Ok(output)
+}
+
+#[test]
+fn wizer_no_imports_by_default() -> Result<()> {
+ let result = wizen(
+ &[],
+ r#"(module
+ (func (export "wizer.initialize"))
+ )"#,
+ )?;
+ assert!(result.status.success());
+
+ let result = wizen(
+ &[],
+ r#"(module
+ (import "foo" "bar" (func))
+ (func (export "wizer.initialize"))
+ )"#,
+ )?;
+ assert!(!result.status.success());
+
+ let result = wizen(
+ &[],
+ r#"(module
+ (import "wasi_snapshot_preview1" "fd_write" (func (param i32 i32 i32 i32) (result i32)))
+ (func (export "wizer.initialize"))
+ )"#,
+ )?;
+ assert!(!result.status.success());
+
+ let result = wizen(
+ &["-Scli"],
+ r#"(module
+ (import "wasi_snapshot_preview1" "fd_write" (func (param i32 i32 i32 i32) (result i32)))
+ (func (export "wizer.initialize"))
+ )"#,
+ )?;
+ assert!(result.status.success());
+
+ Ok(())
+}