Skip to content

Setting process env vars with interior nuls leads to unexpected env for child #30862

Closed
@kamalmarhubi

Description

Noticed by @talchas when discussing #30858.

The environment variables are never checked for interior nuls. This leads to very unexpected results in the child's env. Keys with interior nuls are truncated and have no values, and values are truncated at the nul:

use std::process::Command;

fn main() {
    Command::new("/usr/bin/env").env("a\0b", "c\0d")
                                .env("ab", "c\0d")
                                .status()
                                .unwrap();
}

(playground)

Output:

a
ab=c
USER=rust
HOME=/home/rust
PATH=/usr/local/bin:/usr/bin:/bin
LOGNAME=rust
PWD=/home/rust

Metadata

Assignees

No one assigned

    Labels

    T-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