Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cf410cb

Browse files
committedFeb 1, 2023
Auto merge of #11644 - basile-henry:basile-henry/deny-cargo-home-env-table, r=ehuss
config: Deny CARGO_HOME in [env] table (fixes #11590) Fixes #11590
2 parents a40a64b + 17a2bce commit cf410cb

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed
 

‎src/cargo/util/config/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1685,8 +1685,15 @@ impl Config {
16851685
}
16861686

16871687
pub fn env_config(&self) -> CargoResult<&EnvConfig> {
1688-
self.env_config
1689-
.try_borrow_with(|| self.get::<EnvConfig>("env"))
1688+
let env_config = self
1689+
.env_config
1690+
.try_borrow_with(|| self.get::<EnvConfig>("env"))?;
1691+
1692+
if env_config.get("CARGO_HOME").is_some() {
1693+
bail!("setting the `CARGO_HOME` environment variable is not supported in the `[env]` configuration table")
1694+
}
1695+
1696+
Ok(env_config)
16901697
}
16911698

16921699
/// This is used to validate the `term` table has valid syntax.

‎tests/testsuite/cargo_env_config.rs

+26
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ fn env_invalid() {
5757
.run();
5858
}
5959

60+
#[cargo_test]
61+
fn env_no_cargo_home() {
62+
let p = project()
63+
.file("Cargo.toml", &basic_bin_manifest("foo"))
64+
.file(
65+
"src/main.rs",
66+
r#"
67+
fn main() {
68+
}
69+
"#,
70+
)
71+
.file(
72+
".cargo/config",
73+
r#"
74+
[env]
75+
CARGO_HOME = "/"
76+
"#,
77+
)
78+
.build();
79+
80+
p.cargo("build")
81+
.with_status(101)
82+
.with_stderr_contains("[..]setting the `CARGO_HOME` environment variable is not supported in the `[env]` configuration table")
83+
.run();
84+
}
85+
6086
#[cargo_test]
6187
fn env_force() {
6288
let p = project()

0 commit comments

Comments
 (0)