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

fix: don't strip prefix if path is exactly "." #293

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions cli/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,13 @@ fn cli_issue_280() {
.arg("./src/tests/testdata/")
.assert()
.success();

// Handle special case of just . for path argument.
Command::cargo_bin("yr")
.unwrap()
.arg("scan")
.arg("src/tests/testdata/foo.yar")
.arg(".")
.assert()
.success();
}
20 changes: 14 additions & 6 deletions cli/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,20 @@ impl<'a> Walker<'a> {
// workaround for a bug in globwalk that causes a panic.
// https://github.com/VirusTotal/yara-x/issues/280
// https://github.com/Gilnaa/globwalk/issues/28

#[cfg(not(target_os = "windows"))]
let path = self.path.strip_prefix("./").unwrap_or(self.path);

#[cfg(target_os = "windows")]
let path = self.path.strip_prefix(r#".\"#).unwrap_or(self.path);
//
// Only perform the strip if the path is not exactly "." - this allows
// users to run "yr scan rules.yara ." to scan all the files in the
// current directory.
let path = if self.path.as_os_str().ne(".") {
#[cfg(not(target_os = "windows"))]
let path = self.path.strip_prefix("./").unwrap_or(self.path);

#[cfg(target_os = "windows")]
let path = self.path.strip_prefix(r#".\"#).unwrap_or(self.path);
path
} else {
self.path
};

let mut builder = if self.filters.is_empty() {
globwalk::GlobWalkerBuilder::from_patterns(path, &["**"])
Expand Down
Loading