Skip to content

Commit

Permalink
Fixed crash on missing cwd/exe (metalbear-co#2533)
Browse files Browse the repository at this point in the history
* Fixed crash on missing cwd/exe

* changelog

* format
  • Loading branch information
aviramha authored Jun 18, 2024
1 parent 1323ae2 commit 5ba1cb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/+missing-pwd.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed crash on missing cwd/exe
20 changes: 14 additions & 6 deletions mirrord/layer/src/file/filter/read_local_by_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use regex::RegexSetBuilder;
/// pattern in the `feature.fs.read_only` or `feature.fs.read_write` configuration field,
/// respectively.
pub fn regex_set_builder() -> RegexSetBuilder {
RegexSetBuilder::new([
let mut patterns: Vec<String> = [
r"^.+\.so$",
r"^.+\.d$",
r"^.+\.pyc$",
Expand Down Expand Up @@ -73,10 +73,18 @@ pub fn regex_set_builder() -> RegexSetBuilder {
r"^/Network",
// Any path under the standard temp directory.
&format!("^{}", env::temp_dir().to_string_lossy()),
// Any path with the current dir's whole path as a substring of its path.
&format!("^.*{}.*$", env::current_dir().unwrap().to_string_lossy()),
// Any path with the current exe's whole path as a substring of its path.
&format!("^.*{}.*$", env::current_exe().unwrap().to_string_lossy()),
"^/$", // root
])
]
.iter()
.map(|s| s.to_string())
.collect();

if let Ok(cwd) = env::current_dir() {
patterns.push(format!("^.*{}.*$", cwd.to_string_lossy()));
}
if let Ok(executable) = env::current_exe() {
patterns.push(format!("^.*{}.*$", executable.to_string_lossy()));
}

RegexSetBuilder::new(patterns)
}

0 comments on commit 5ba1cb8

Please sign in to comment.