From a1457de50fc39d35c585d5196aa6d9e7585a3590 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 26 Oct 2020 15:56:50 +0100 Subject: [PATCH 1/3] feat(wasi) Allow the `=` sign in the environment variable value. Having `a=b` means that the environment variable key is `a`, and its value is `b`. Having `a=b=c` means that the key is `a` and its value is `b=c`. It's OK to get this, e.g. within a CGI context where values can hold strings such as `sec-ch-ua: "Chromium;v=86"` etc. See https://github.com/wasmerio/wasmer/issues/1708 for a longer explanation. --- lib/wasi/src/state/builder.rs | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/wasi/src/state/builder.rs b/lib/wasi/src/state/builder.rs index f6694bb021a..74f4676eda6 100644 --- a/lib/wasi/src/state/builder.rs +++ b/lib/wasi/src/state/builder.rs @@ -328,33 +328,15 @@ impl WasiStateBuilder { } } } + for env in self.envs.iter() { - let mut eq_seen = false; - for b in env.iter() { - match *b { - b'=' => { - if eq_seen { - return Err(WasiStateCreationError::EnvironmentVariableFormatError( - format!( - "found '=' in env var string \"{}\" (key=value)", - std::str::from_utf8(env) - .unwrap_or("Inner error: env var is invalid_utf8!") - ), - )); - } - eq_seen = true; - } - 0 => { - return Err(WasiStateCreationError::EnvironmentVariableFormatError( - format!( - "found nul byte in env var string \"{}\" (key=value)", - std::str::from_utf8(env) - .unwrap_or("Inner error: env var is invalid_utf8!") - ), - )); - } - _ => (), - } + if env.iter().find(|&&ch| ch == 0).is_some() { + return Err(WasiStateCreationError::EnvironmentVariableFormatError( + format!( + "found nul byte in env var string \"{}\" (key=value)", + std::str::from_utf8(env).unwrap_or("Inner error: env var is invalid_utf8!") + ), + )); } } From 32c08b5c6794149a7a7127320168070b8640b381 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 26 Oct 2020 15:59:23 +0100 Subject: [PATCH 2/3] test(wasi) Update test cases according to the previous commit. --- lib/wasi/src/state/builder.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/wasi/src/state/builder.rs b/lib/wasi/src/state/builder.rs index 74f4676eda6..ed59ecb2605 100644 --- a/lib/wasi/src/state/builder.rs +++ b/lib/wasi/src/state/builder.rs @@ -490,17 +490,21 @@ mod test { #[test] fn env_var_errors() { + // `a=b` means key is `a` and value is `b`, which is OK. + // `a=b=c` means key is `a` and value is `b=c`, which is OK too. let output = create_wasi_state("test_prog") - .env("HOM=E", "/home/home") + .env("HOME", "/home/home=foo") .build(); + match output { - Err(WasiStateCreationError::EnvironmentVariableFormatError(_)) => assert!(true), - _ => assert!(false), + Err(WasiStateCreationError::EnvironmentVariableFormatError(_)) => assert!(false), + _ => assert!(true), } let output = create_wasi_state("test_prog") .env("HOME\0", "/home/home") .build(); + match output { Err(WasiStateCreationError::EnvironmentVariableFormatError(_)) => assert!(true), _ => assert!(false), From 41c22d2369fa50bfd9fa4d91bb2a22e6389a8185 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 26 Oct 2020 16:01:49 +0100 Subject: [PATCH 3/3] doc(changelog) Add #1762. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4621db71a3e..a9c7b93ef7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ - [#1709](https://github.com/wasmerio/wasmer/pull/1709) Implement `wasm_module_name` and `wasm_module_set_name` in the Wasm(er) C API. - [#1700](https://github.com/wasmerio/wasmer/pull/1700) Implement `wasm_externtype_copy` in the Wasm C API. +### Changed + +- [#1762](https://github.com/wasmerio/wasmer/pull/1762) Allow the `=` sign in a WASI environment variable value. + ### Fixed - [#1718](https://github.com/wasmerio/wasmer/pull/1718) Fix panic in the API in some situations when the memory's min bound was greater than the memory's max bound.