Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wasi) Allow the = sign in the environment variable value. #1762

Merged
merged 8 commits into from
Oct 27, 2020
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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.
Expand Down
44 changes: 15 additions & 29 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Hywan marked this conversation as resolved.
Show resolved Hide resolved
),
));
}
}

Expand Down Expand Up @@ -508,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")
Hywan marked this conversation as resolved.
Show resolved Hide resolved
.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),
Expand Down