Skip to content

Commit 314649d

Browse files
committed
Check Windows env keys for interior =
1 parent 742089d commit 314649d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/libstd/sys/windows/process.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ fn ensure_no_nuls<T: AsRef<OsStr>>(str: T) -> io::Result<T> {
4949
}
5050
}
5151

52+
fn ensure_valid_env_key<T: AsRef<OsStr>>(str: T) -> io::Result<T> {
53+
if str.as_ref().is_empty() || str.as_ref().encode_wide().skip(1).any(|b| b == b'=' as u16) {
54+
Err(io::Error::new(io::ErrorKind::InvalidInput,
55+
"malformed env key in provided data"))
56+
} else {
57+
ensure_no_nuls(str)
58+
}
59+
}
60+
5261
pub struct Command {
5362
program: OsString,
5463
args: Vec<OsString>,
@@ -479,7 +488,7 @@ fn make_envp(env: Option<&collections::HashMap<OsString, OsString>>)
479488
let mut blk = Vec::new();
480489

481490
for pair in env {
482-
blk.extend(ensure_no_nuls(pair.0)?.encode_wide());
491+
blk.extend(ensure_valid_env_key(pair.0)?.encode_wide());
483492
blk.push('=' as u16);
484493
blk.extend(ensure_no_nuls(pair.1)?.encode_wide());
485494
blk.push(0);

0 commit comments

Comments
 (0)