diff options
| author | Kamal Marhubi <kamal@marhubi.com> | 2016-01-15 15:29:45 -0500 |
|---|---|---|
| committer | Kamal Marhubi <kamal@marhubi.com> | 2016-02-03 10:54:29 -0500 |
| commit | 7c64bf1b9b6e8e97ab652a4922f1c0e68ebc77f0 (patch) | |
| tree | 52eef97ff332e10c18c7469df5d296fc4f64ef0f /src/libstd/process.rs | |
| parent | 28bed3f5e64dfc083dc193412b65d95533a61d72 (diff) | |
| download | rust-7c64bf1b9b6e8e97ab652a4922f1c0e68ebc77f0.tar.gz rust-7c64bf1b9b6e8e97ab652a4922f1c0e68ebc77f0.zip | |
std: Properly handle interior NULs in std::process
This reports an error at the point of calling `Command::spawn()` or one of its equivalents. Fixes https://github.com/rust-lang/rust/issues/30858 Fixes https://github.com/rust-lang/rust/issues/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 7197dfa8b2d..2456226b54c 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -343,11 +343,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) } } @@ -877,4 +873,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!(), + } + } } |
