Skip to content

Commit

Permalink
Auto merge of #11644 - basile-henry:basile-henry/deny-cargo-home-env-…
Browse files Browse the repository at this point in the history
…table, r=ehuss

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

Fixes #11590
  • Loading branch information
bors committed Feb 1, 2023
2 parents a40a64b + 17a2bce commit cf410cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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!("setting the `CARGO_HOME` environment variable is not supported in the `[env]` configuration table")
}

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("[..]setting the `CARGO_HOME` environment variable is not supported in the `[env]` configuration table")
.run();
}

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

0 comments on commit cf410cb

Please sign in to comment.