diff options
| author | bors <bors@rust-lang.org> | 2016-02-03 17:19:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-02-03 17:19:10 +0000 |
| commit | 8fc73c703ab175577346773ad93de3aa2c3f44a2 (patch) | |
| tree | 9c216479a0cb6f7386625a4393d7ec4feb73d241 /src/libstd/process.rs | |
| parent | b14af1e4ef5d514ca5b2282be5938e4b7417e770 (diff) | |
| parent | 7c64bf1b9b6e8e97ab652a4922f1c0e68ebc77f0 (diff) | |
| download | rust-8fc73c703ab175577346773ad93de3aa2c3f44a2.tar.gz rust-8fc73c703ab175577346773ad93de3aa2c3f44a2.zip | |
Auto merge of #31056 - kamalmarhubi:std-process-nul-chars, r=alexcrichton
This reports an error at the point of calling `Command::spawn()` or one of its equivalents. Fixes #30858 Fixes #30862
Diffstat (limited to 'src/libstd/process.rs')
| -rw-r--r-- | src/libstd/process.rs | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 5e0a54392d2..a8da11420d8 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -353,11 +353,7 @@ impl fmt::Debug for Command { /// non-utf8 data is lossily converted using the utf8 replacement /// character. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{:?}", self.inner.program)); - for arg in &self.inner.args { - try!(write!(f, " {:?}", arg)); - } - Ok(()) + self.inner.fmt(f) } } @@ -887,4 +883,54 @@ mod tests { assert!(output.contains("RUN_TEST_NEW_ENV=123"), "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); } + + // Regression tests for #30858. + #[test] + fn test_interior_nul_in_progname_is_error() { + match Command::new("has-some-\0\0s-inside").spawn() { + Err(e) => assert_eq!(e.kind(), ErrorKind::InvalidInput), + Ok(_) => panic!(), + } + } + + #[test] + fn test_interior_nul_in_arg_is_error() { + match Command::new("echo").arg("has-some-\0\0s-inside").spawn() { + Err(e) => assert_eq!(e.kind(), ErrorKind::InvalidInput), + Ok(_) => panic!(), + } + } + + #[test] + fn test_interior_nul_in_args_is_error() { + match Command::new("echo").args(&["has-some-\0\0s-inside"]).spawn() { + Err(e) => assert_eq!(e.kind(), ErrorKind::InvalidInput), + Ok(_) => panic!(), + } + } + + #[test] + fn test_interior_nul_in_current_dir_is_error() { + match Command::new("echo").current_dir("has-some-\0\0s-inside").spawn() { + Err(e) => assert_eq!(e.kind(), ErrorKind::InvalidInput), + Ok(_) => panic!(), + } + } + + // Regression tests for #30862. + #[test] + fn test_interior_nul_in_env_key_is_error() { + match env_cmd().env("has-some-\0\0s-inside", "value").spawn() { + Err(e) => assert_eq!(e.kind(), ErrorKind::InvalidInput), + Ok(_) => panic!(), + } + } + + #[test] + fn test_interior_nul_in_env_value_is_error() { + match env_cmd().env("key", "has-some-\0\0s-inside").spawn() { + Err(e) => assert_eq!(e.kind(), ErrorKind::InvalidInput), + Ok(_) => panic!(), + } + } } |
