Setting process env vars with interior nuls leads to unexpected env for child #30862
Closed
Description
Noticed by @talchas when discussing #30858.
The environment variables are never checked for interior nuls. This leads to very unexpected results in the child's env. Keys with interior nuls are truncated and have no values, and values are truncated at the nul:
use std::process::Command;
fn main() {
Command::new("/usr/bin/env").env("a\0b", "c\0d")
.env("ab", "c\0d")
.status()
.unwrap();
}
Output:
a
ab=c
USER=rust
HOME=/home/rust
PATH=/usr/local/bin:/usr/bin:/bin
LOGNAME=rust
PWD=/home/rust