Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: prevent CreateProcess() race on Windows #20650

Merged
merged 1 commit into from
Jan 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libstd/sys/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ use path::BytesContainer;
use ptr;
use str;
use sys::fs::FileDesc;
use sync::{StaticMutex, MUTEX_INIT};

use sys::fs;
use sys::{self, retry, c, wouldblock, set_nonblocking, ms_to_timeval, timer};
use sys_common::helper_thread::Helper;
use sys_common::{AsInner, mkerr_libc, timeout};

pub use sys_common::ProcessConfig;

// `CreateProcess` is racy!
// http://support.microsoft.com/kb/315939
static CREATE_PROCESS_LOCK: StaticMutex = MUTEX_INIT;

/// A value representing a child process.
///
/// The lifetime of this value is linked to the lifetime of the actual
Expand Down Expand Up @@ -224,6 +230,7 @@ impl Process {
with_dirp(cfg.cwd(), |dirp| {
let mut cmd_str: Vec<u16> = cmd_str.utf16_units().collect();
cmd_str.push(0);
let _lock = CREATE_PROCESS_LOCK.lock().unwrap();
let created = CreateProcessW(ptr::null(),
cmd_str.as_mut_ptr(),
ptr::null_mut(),
Expand Down