Skip to content

Cargo binaries are not run in pristine environment #2888

Closed
@nagisa

Description

@nagisa

cargo pollutes the environment with a lot of stuff, thus potentially skewing the behaviour of binaries run with cargo run and directly.

$ bash -c 'env -i PATH="$PATH" HOME="$HOME" ~/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo run'
     Running `target/debug/tst`
("PATH", "/home/nagisa/local/bin:/usr/bin/:/usr/sbin/::/home/nagisa/.cargo/bin/")
("HOME", "/home/nagisa")
("SSL_CERT_FILE", "/etc/ssl/cert.pem")
("SSL_CERT_DIR", "/etc/ssl/certs")
("CARGO_PKG_VERSION_MAJOR", "0")
("CARGO_PKG_VERSION_MINOR", "1")
("CARGO_MANIFEST_DIR", "/tmp/tst")
("CARGO_PKG_VERSION_PATCH", "0")
("CARGO_PKG_HOMEPAGE", "")
("CARGO_PKG_VERSION", "0.1.0")
("CARGO_PKG_AUTHORS", "Simonas Kazlauskas <[email protected]>")
("CARGO_PKG_NAME", "tst")
("LD_LIBRARY_PATH", "/tmp/tst/target/debug:/tmp/tst/target/debug/deps")
("CARGO_PKG_VERSION_PRE", "")
("CARGO_PKG_DESCRIPTION", "")
("OUT_DIR", "/tmp/tst/target/debug/build/tst-023656d15f5dd082/out")
$ bash -c 'env -i PATH="$PATH" HOME="$HOME" ./target/debug/tst'
("PATH", "/home/nagisa/local/bin:/usr/bin/:/usr/sbin/::/home/nagisa/.cargo/bin/")
("HOME", "/home/nagisa")

Most notably, the $LD_LIBRARY_PATH may result in binaries not “just” working when run without cargo run, but also susceptible are SSL_* things. I do not see anybody removing the $LD_LIBRARY_PATH hack, but ideally all other environment variables would just not exist.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions