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

config: Deny CARGO_HOME in [env] table (fixes #11590) #11644

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1685,8 +1685,15 @@ impl Config {
}

pub fn env_config(&self) -> CargoResult<&EnvConfig> {
self.env_config
.try_borrow_with(|| self.get::<EnvConfig>("env"))
let env_config = self
.env_config
.try_borrow_with(|| self.get::<EnvConfig>("env"))?;

if env_config.get("CARGO_HOME").is_some() {
bail!("`CARGO_HOME` environment variable should be not be set in `.cargo/config` via `env.CARGO_HOME` as cargo does not use this value directly (only recursive calls to cargo would)");
basile-henry marked this conversation as resolved.
Show resolved Hide resolved
}

Ok(env_config)
}

/// This is used to validate the `term` table has valid syntax.
Expand Down
26 changes: 26 additions & 0 deletions tests/testsuite/cargo_env_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ fn env_invalid() {
.run();
}

#[cargo_test]
fn env_no_cargo_home() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file(
"src/main.rs",
r#"
fn main() {
}
"#,
)
.file(
".cargo/config",
r#"
[env]
CARGO_HOME = "/"
"#,
)
.build();

p.cargo("build")
.with_status(101)
.with_stderr_contains("[..]`CARGO_HOME` environment variable should be not be set in `.cargo/config` via `env.CARGO_HOME` as cargo does not use this value directly (only recursive calls to cargo would)")
.run();
}

#[cargo_test]
fn env_force() {
let p = project()
Expand Down