Skip to content

Commit

Permalink
Try #1762:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Oct 26, 2020
2 parents c6978ea + 41c22d2 commit b1c22b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
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!")
),
));
}
}

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")
.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

0 comments on commit b1c22b5

Please sign in to comment.