Skip to content

Commit 83c00d2

Browse files
committed
Implement fix for build scripts in output directories
1 parent e75927d commit 83c00d2

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

src/config.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,11 @@ fn extend_from_string_array(vec: &mut Vec<String>, value: Option<&toml::Value>)
5858
}
5959
}
6060

61-
pub fn allowed() -> bool {
62-
directory_allowed() || package_allowed()
61+
pub fn directory_allowed(path: &Path) -> bool {
62+
CONFIG.directories.iter().any(|d| path.starts_with(d))
6363
}
6464

65-
pub fn directory_allowed() -> bool {
66-
let Ok(cwd) = env::current_dir() else {
67-
return false;
68-
};
69-
CONFIG.directories.iter().any(|d| cwd.starts_with(d))
70-
}
71-
72-
fn package_allowed() -> bool {
65+
pub fn package_allowed() -> bool {
7366
let Ok(name) = env::var("CARGO_PKG_NAME") else {
7467
return false;
7568
};

src/linking.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub fn link(args: &[String]) -> Result<()> {
2121
&& var_os("RUSTC_WORKSPACE_WRAPPER").is_none()
2222
&& let Some(path) = output_path(args.iter())
2323
&& is_build_script(&path)
24-
&& !config::allowed()
24+
&& !config::directory_allowed(&path)
25+
&& !config::package_allowed()
2526
{
2627
wrap(&linker, &path)?;
2728
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{Context, Result, bail};
22
use regex::Regex;
33
use std::{
44
collections::BTreeMap,
5-
env::{args, current_exe},
5+
env::{args, current_dir, current_exe},
66
fs::read_to_string,
77
io::{IsTerminal, stdout},
88
path::Path,
@@ -87,7 +87,7 @@ A linker replacement to help protect against malicious build scripts
8787
let result = enabled();
8888
if matches!(result, Ok(true)) {
8989
let enabled = *ENABLED;
90-
if config::directory_allowed() {
90+
if current_dir().is_ok_and(|cwd| config::directory_allowed(&cwd)) {
9191
let disabled = *DISABLED_YELLOW;
9292
println!("build-wrap is {enabled} (but {disabled} in this directory)");
9393
} else {

0 commit comments

Comments
 (0)