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

[casr-python][casr-java] Add sub-tool option #115

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions casr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ reqwest = { version = "0.11", features = ["json", "multipart", "rustls-tls"], de
tokio = { version = "1", features = ["rt", "macros"], optional = true }
toml = { version = "0.7", optional = true }
wait-timeout = "0.2"
which = "4.4"

libcasr = { path = "../libcasr", version = "2.7.0", features = ["serde", "exploitable"] }

Expand Down
15 changes: 13 additions & 2 deletions casr/src/bin/casr-java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ fn main() -> Result<()> {
.value_name("FILE")
.help("File with regular expressions for functions and file paths that should be ignored"),
)
.arg(
Arg::new("sub-tool")
.long("sub-tool")
.default_value("casr-san")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(PathBuf))
SweetVishnya marked this conversation as resolved.
Show resolved Hide resolved
.value_name("BIN")
SweetVishnya marked this conversation as resolved.
Show resolved Hide resolved
.help(
"Path to sub tool for crash analysis that will be called when main tool fails to detect a crash",
),
)
.arg(
Arg::new("ARGS")
.action(ArgAction::Set)
Expand Down Expand Up @@ -135,8 +146,8 @@ fn main() -> Result<()> {
report.execution_class = exception;
}
} else {
// Call casr-san
return util::call_casr_san(&matches, &argv, "casr-java");
// Call sub tool
return util::call_sub_tool(&matches, &argv, "casr-java");
}

if let Ok(crash_line) = JavaStacktrace::parse_stacktrace(&report.stacktrace)?.crash_line() {
Expand Down
19 changes: 15 additions & 4 deletions casr/src/bin/casr-python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ fn main() -> Result<()> {
.value_name("FILE")
.help("File with regular expressions for functions and file paths that should be ignored"),
)
.arg(
Arg::new("sub-tool")
.long("sub-tool")
.default_value("casr-san")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(PathBuf))
.value_name("BIN")
.help(
"Path to sub tool for crash analysis that will be called when main tool fails to detect a crash",
SweetVishnya marked this conversation as resolved.
Show resolved Hide resolved
),
)
.arg(
Arg::new("ARGS")
.action(ArgAction::Set)
Expand Down Expand Up @@ -138,8 +149,8 @@ fn main() -> Result<()> {
}
}
} else {
// Call casr-san
return util::call_casr_san(&matches, &argv, "casr-python");
// Call sub tool
return util::call_sub_tool(&matches, &argv, "casr-python");
}
} else if let Some(report_start) = python_stderr_list
.iter()
Expand All @@ -160,8 +171,8 @@ fn main() -> Result<()> {
report.execution_class = exception;
}
} else {
// Call casr-san
return util::call_casr_san(&matches, &argv, "casr-python");
// Call sub tool
return util::call_sub_tool(&matches, &argv, "casr-python");
}

if let Ok(crash_line) = PythonStacktrace::parse_stacktrace(&report.stacktrace)?.crash_line() {
Expand Down
24 changes: 19 additions & 5 deletions casr/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,35 @@ use simplelog::*;
use std::fs::OpenOptions;
use std::io::Write;
use std::io::{BufRead, BufReader};
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::RwLock;
use which::which;

/// Call casr-san with the provided options
/// Call sub tool with the provided options
///
/// # Arguments
///
/// * `matches` - casr options
///
/// * `tool` - tool, that called casr-san
/// * `name` - main tool name, that called sub tool
///
/// * `argv` - executable file options
pub fn call_casr_san(matches: &ArgMatches, argv: &[&str], tool: &str) -> Result<()> {
let mut cmd = Command::new("casr-san");
pub fn call_sub_tool(matches: &ArgMatches, argv: &[&str], name: &str) -> Result<()> {
let tool = matches.get_one::<PathBuf>("sub-tool").unwrap();
if let Err(_) = which(tool) {
if !tool.exists() {
bail!("Sub tool {tool:?} doesn't exist");
}
if !tool.is_file() {
bail!("Sub tool {tool:?} isn't exist");
SweetVishnya marked this conversation as resolved.
Show resolved Hide resolved
}
if tool.metadata()?.permissions().mode() & 0o111 == 0 {
bail!("Sub tool {tool:?} isn't executable");
}
}
let mut cmd = Command::new(tool);
if let Some(report_path) = matches.get_one::<PathBuf>("output") {
cmd.args(["--output", report_path.to_str().unwrap()]);
} else {
Expand All @@ -50,7 +64,7 @@ pub fn call_casr_san(matches: &ArgMatches, argv: &[&str], tool: &str) -> Result<
if output.status.success() {
Ok(())
} else {
bail!("casr-san error when calling from {tool}");
bail!("{tool:?} error when calling from {name}");
}
}

Expand Down
Loading