env --file FILE parses an .env/INI file and passes each key and value straight to std::env::set_var, which panics when either contains a NUL byte. A single NUL anywhere in the file therefore aborts env with a Rust panic instead of a diagnostic.
The argv path (env NAME=VALUE ...) is guarded — apply_specified_env_vars checks for an empty name before calling set_var, but the --file path has no guard at all.
Steps to reproduce
A NUL in the value:
$ printf 'KEY=a\x00b\n' > conf.env
$ env --file conf.env
thread 'main' panicked at library/std/src/env.rs:361:9:
failed to set environment variable `"KEY"` to `"a\0b"`: file name contained an unexpected NUL byte
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
134
A NUL in the key does the same:
$ printf 'a\x00b=c\n' > k.env
$ env --file k.env # exit 134, identical panic
Root cause
|
for (_, prop) in &conf { |
|
// ignore all INI section lines (treat them as comments) |
|
for (key, value) in prop { |
|
unsafe { |
|
env::set_var(key, value); |
|
} |
|
} |
|
} |
std::env::set_var panics if either argument contains a NUL. Nothing between the parser and this call validates the bytes.
env --file FILEparses an.env/INI file and passes each key and value straight tostd::env::set_var, which panics when either contains a NUL byte. A single NUL anywhere in the file therefore abortsenvwith a Rust panic instead of a diagnostic.The argv path (
env NAME=VALUE ...) is guarded —apply_specified_env_varschecks for an empty name before callingset_var, but the--filepath has no guard at all.Steps to reproduce
A NUL in the value:
A NUL in the key does the same:
Root cause
coreutils/src/uu/env/src/env.rs
Lines 331 to 338 in 2c0e1b9
std::env::set_varpanics if either argument contains a NUL. Nothing between the parser and this call validates the bytes.