about summary refs log tree commit diff
path: root/src/libstd/sys/unix/process/process_common.rs
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2018-10-25 19:44:32 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2018-11-01 12:51:24 +0000
commit36fe3b605a7a7143a14565272140ba1b43c1b041 (patch)
treeb6e50e01308ebee18923dbf6d22d3f81338549c5 /src/libstd/sys/unix/process/process_common.rs
parent365b9001e588cf3d91561894b0e44389e31ae000 (diff)
downloadrust-36fe3b605a7a7143a14565272140ba1b43c1b041.tar.gz
rust-36fe3b605a7a7143a14565272140ba1b43c1b041.zip
Fixes #46775 -- don't mutate the process's environment in Command::exec
Instead, pass the environment to execvpe, so the kernel can apply it directly to the new process. This avoids a use-after-free in the case where exec'ing the new process fails for any reason, as well as a race condition if there are other threads alive during the exec.
Diffstat (limited to 'src/libstd/sys/unix/process/process_common.rs')
-rw-r--r--src/libstd/sys/unix/process/process_common.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/process/process_common.rs b/src/libstd/sys/unix/process/process_common.rs
index 77f125f3c5b..3d5920dfb69 100644
--- a/src/libstd/sys/unix/process/process_common.rs
+++ b/src/libstd/sys/unix/process/process_common.rs
@@ -141,6 +141,10 @@ impl Command {
     pub fn get_argv(&self) -> &Vec<*const c_char> {
         &self.argv.0
     }
+    #[cfg(not(target_os = "fuchsia"))]
+    pub fn get_program(&self) -> &CString {
+        return &self.program;
+    }
 
     #[allow(dead_code)]
     pub fn get_cwd(&self) -> &Option<CString> {
@@ -244,6 +248,10 @@ impl CStringArray {
     pub fn as_ptr(&self) -> *const *const c_char {
         self.ptrs.as_ptr()
     }
+    #[cfg(not(target_os = "fuchsia"))]
+    pub fn get_items(&self) -> &[CString] {
+        return &self.items;
+    }
 }
 
 fn construct_envp(env: BTreeMap<DefaultEnvKey, OsString>, saw_nul: &mut bool) -> CStringArray {