Skip to content

Commit

Permalink
Find absolute path for tool in casr-js
Browse files Browse the repository at this point in the history
  • Loading branch information
PaDarochek committed Nov 8, 2023
1 parent 305f346 commit 94a46a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ Cargo.lock
*/Cargo.lock
*/tests/tmp_tests_casr
*.swp
node_modules
*/node_modules/*
16 changes: 12 additions & 4 deletions casr/src/bin/casr-js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,22 @@ fn main() -> Result<()> {
let mut report = CrashReport::new();
// Set executable path.
report.executable_path = argv[0].to_string();
let mut path_to_tool = PathBuf::new();
path_to_tool.push(argv[0]);
if argv.len() > 1 {
if let Some(fname) = Path::new(argv[0]).file_name() {
let Ok(full_path_to_tool) = which::which(fname) else {
bail!("Could not get the full path of {}", argv[0]);
};
path_to_tool = full_path_to_tool;
let fname = fname.to_string_lossy();
if (fname.starts_with("node") || fname.starts_with("jsfuzz"))
if (fname.ends_with("node") || fname.ends_with("jsfuzz"))
&& !fname.ends_with(".js")
&& argv[1].ends_with(".js")
{
report.executable_path = argv[1].to_string();
} else if argv.len() > 2
&& fname.starts_with("npx")
&& fname.ends_with("npx")
&& !fname.ends_with(".js")
&& argv[1] == "jazzer"
&& argv[2].ends_with(".js")
Expand All @@ -138,8 +144,10 @@ fn main() -> Result<()> {
report.execution_class = exception;
}
} else {

Check warning on line 146 in casr/src/bin/casr-js.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-js.rs#L101-L146

Added lines #L101 - L146 were not covered by tests
// Call casr-san
return util::call_casr_san(&matches, &argv, "casr-js");
// Call casr-san with absolute path to interpreter/fuzzer
let mut modified_argv = argv.clone();
modified_argv[0] = path_to_tool.to_str().unwrap_or(argv[0]);
return util::call_casr_san(&matches, &modified_argv, "casr-js");
}

Check warning on line 151 in casr/src/bin/casr-js.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-js.rs#L148-L151

Added lines #L148 - L151 were not covered by tests

if let Ok(crash_line) = JsStacktrace::parse_stacktrace(&report.stacktrace)?.crash_line() {
Expand Down
2 changes: 1 addition & 1 deletion casr/src/bin/casr-libfuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn main() -> Result<()> {
} else if argv[0].ends_with("jazzer") || argv[0].ends_with("java") {
"casr-java"
} else if argv[0].ends_with("node")
|| argv.len() > 1 && argv[0].ends_with("npx") && argv[1].ends_with("jazzer")
|| argv.len() > 1 && argv[0].ends_with("npx") && argv[1] == "jazzer"
|| argv[0].ends_with("jsfuzz")
{
"casr-js"

Check warning on line 135 in casr/src/bin/casr-libfuzzer.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-libfuzzer.rs#L134-L135

Added lines #L134 - L135 were not covered by tests
Expand Down

0 comments on commit 94a46a4

Please sign in to comment.