Skip to content

windows: when creating process with redirected stdio, make parent's std handles not inheritable #54760

Open
@ikostia

Description

@ikostia

Currently, if this happens:

use std::process::Command;
...
Command::new("child.exe")
        .stdin(Stdio::null())
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .spawn()

the child.exe accidentally inherits stdin, stdout and stderr handles of the parent process. This can be bad, because the objects these handles point to (say pipes), may be watched by some third process.

Since at the point of creating a child process we know that it does not need our std handles (because it's explicitly being created with Stdio::null()), we can temporarily disable handle inheritance on these handles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-processArea: `std::process` and `std::env`O-windowsOperating system: WindowsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions