File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff 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+
5261pub 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 ) ;
You can’t perform that action at this time.
0 commit comments