Skip to content

Commit 2a5d294

Browse files
authored
Fix LibAFL crash directory filter (#264)
1 parent 6bd36d9 commit 2a5d294

22 files changed

Lines changed: 354 additions & 335 deletions

casr/src/bin/casr-cli.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,11 +1013,12 @@ fn print_summary(dir: &Path, unique_crash_line: bool, strip_path: Option<&String
10131013
println!("==> <{}>", filename.magenta());
10141014
for info in cluster_hash.values() {
10151015
let mut path = info.0.last().unwrap().clone();
1016-
if let Some(prefix) = strip_path {
1017-
if let Ok(stripped) = Path::new(&path).strip_prefix(prefix) {
1018-
path = stripped.display().to_string();
1019-
}
1016+
if let Some(prefix) = strip_path
1017+
&& let Ok(stripped) = Path::new(&path).strip_prefix(prefix)
1018+
{
1019+
path = stripped.display().to_string();
10201020
}
1021+
10211022
if ubsan {
10221023
// /path/to/report.casrep: Description: crashline (path:line:column)
10231024
println!("{}: {}", path, info.0[0]);
@@ -1082,11 +1083,12 @@ fn process_report(
10821083
return None;
10831084
};
10841085
let mut report = report.to_string();
1085-
if let Some(prefix) = strip_path {
1086-
if let Ok(stripped) = Path::new(&report).strip_prefix(prefix) {
1087-
report = stripped.display().to_string();
1088-
}
1086+
if let Some(prefix) = strip_path
1087+
&& let Ok(stripped) = Path::new(&report).strip_prefix(prefix)
1088+
{
1089+
report = stripped.display().to_string();
10891090
}
1091+
10901092
let Ok(jreport): Result<Value, _> = serde_json::from_reader(BufReader::new(file)) else {
10911093
return None;
10921094
};

casr/src/bin/casr-core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn main() -> Result<()> {
219219
report.pid = pid;
220220
// Add network connections.
221221
if let Err(error) = report.add_network_connections() {
222-
error!("{}", error);
222+
error!("{error}");
223223
}
224224

225225
file_name_to_save.push_str(&format!("_{}", report.date));

casr/src/bin/casr-csharp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ fn main() -> Result<()> {
163163
let stacktrace = CSharpStacktrace::parse_stacktrace(&report.stacktrace)?;
164164
if let Ok(crash_line) = stacktrace.crash_line() {
165165
report.crashline = crash_line.to_string();
166-
if let CrashLine::Source(debug) = crash_line {
167-
if let Some(sources) = CrashReport::sources(&debug) {
168-
report.source = sources;
169-
}
166+
if let CrashLine::Source(debug) = crash_line
167+
&& let Some(sources) = CrashReport::sources(&debug)
168+
{
169+
report.source = sources;
170170
}
171171
}
172172

casr/src/bin/casr-dojo.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,25 @@ impl DefectDojoClient {
104104
};
105105

106106
// Get existing entity.
107-
info!("Trying to find existing {}", entity_name);
107+
info!("Trying to find existing {entity_name}");
108108
let response = self.request(GET, &url)?.query(&query).send().await?;
109109
let results = get_results(response).await?;
110110
if !results.is_empty() {
111111
let id = get_result_id(&results[0])?;
112-
info!("Found existing {} with id={}", entity_name, id);
112+
info!("Found existing {entity_name} with id={id}");
113113
return Ok(id);
114114
}
115115

116116
// Create new entity.
117-
info!("Didn't find {} - creating a new one", entity_name);
117+
info!("Didn't find {entity_name} - creating a new one");
118118
let response = self.request(POST, &url)?.json(toml).send().await?;
119119
if let Err(e) = response.error_for_status_ref() {
120120
error!("{}", response.text().await?);
121-
bail!("{}", e);
121+
bail!("{e}");
122122
}
123123
let json: serde_json::Value = response.json().await?;
124124
let id = get_result_id(&json)?;
125-
info!("Created new {} with id={}", entity_name, id);
125+
info!("Created new {entity_name} with id={id}");
126126
Ok(id)
127127
}
128128

@@ -161,16 +161,16 @@ impl DefectDojoClient {
161161
let response = self.request(GET, &file_url)?.send().await?;
162162
if let Err(e) = response.error_for_status_ref() {
163163
error!("{}", response.text().await?);
164-
bail!("{}", e);
164+
bail!("{e}");
165165
}
166166
let report = response.json::<CrashReport>().await;
167167
if let Err(e) = report {
168-
error!("Failed to parse CASR report {}: {}", file_url, e);
168+
error!("Failed to parse CASR report {file_url}: {e}");
169169
return Ok(None);
170170
}
171171
let hash = compute_report_hash(&report.unwrap(), &file_url);
172172
if let Err(e) = hash {
173-
error!("{}", e);
173+
error!("{e}");
174174
return Ok(None);
175175
}
176176
return Ok(Some(hash.unwrap()));
@@ -198,7 +198,7 @@ impl DefectDojoClient {
198198
let response = self.request(POST, &url)?.multipart(form).send().await?;
199199
if let Err(e) = response.error_for_status_ref() {
200200
error!("{}", response.text().await?);
201-
bail!("{}", e);
201+
bail!("{e}");
202202
}
203203
Ok(())
204204
}
@@ -329,14 +329,11 @@ impl DefectDojoClient {
329329
}
330330
let response: serde_json::Value = response.json().await?;
331331
let id = get_result_id(&response)?;
332-
debug!("Created new finding '{}' with id={}", title, id);
332+
debug!("Created new finding '{title}' with id={id}");
333333

334334
// Upload CASR report.
335335
self.upload_file(&path, "casrep.json", "CASR", id).await?;
336-
debug!(
337-
"Uploaded CASR report for finding '{}' with id={}",
338-
title, id
339-
);
336+
debug!("Uploaded CASR report for finding '{title}' with id={id}");
340337

341338
// Upload additional CASR report from GDB.
342339
if gdb.is_some() {
@@ -347,23 +344,21 @@ impl DefectDojoClient {
347344
id,
348345
)
349346
.await?;
350-
debug!(
351-
"Uploaded CASR GDB report for finding '{}' with id={}",
352-
title, id
353-
);
347+
debug!("Uploaded CASR GDB report for finding '{title}' with id={id}");
354348
}
355349

356350
// Upload crash seed.
357351
let mut crash_path = path.with_extension("");
358-
if let Some(ext) = crash_path.extension() {
359-
if ext == "gdb" {
360-
crash_path = crash_path.with_extension("");
361-
}
352+
if let Some(ext) = crash_path.extension()
353+
&& ext == "gdb"
354+
{
355+
crash_path = crash_path.with_extension("");
362356
}
357+
363358
if crash_path.exists() {
364359
self.upload_file(&crash_path, ".txt", "Crash seed", id)
365360
.await?;
366-
debug!("Uploaded crash seed for finding '{}' with id={}", title, id);
361+
debug!("Uploaded crash seed for finding '{title}' with id={id}");
367362
}
368363

369364
Ok(())
@@ -785,7 +780,7 @@ async fn main() -> Result<()> {
785780
toml::Value::String(test_type_name.to_string()),
786781
);
787782
test_type.insert("dynamic_tool".to_string(), toml::Value::Boolean(true));
788-
info!("Getting id for test type '{}'", test_type_name);
783+
info!("Getting id for test type '{test_type_name}'");
789784
let test_type_id = client.get_or_create_entity(&test_type, "test_type").await?;
790785
test.insert("test_type".to_string(), toml::Value::Integer(test_type_id));
791786
}
@@ -822,10 +817,7 @@ async fn main() -> Result<()> {
822817
]);
823818

824819
// Wait for findings responses.
825-
info!(
826-
"Getting all active, false positive, and out of scope findings for {}",
827-
product_name
828-
);
820+
info!("Getting all active, false positive, and out of scope findings for {product_name}");
829821
let mut findings = Vec::new();
830822
let mut tasks = tokio::task::JoinSet::new();
831823
tasks.spawn(async move { get_findings_ids(active).await });
@@ -912,7 +904,7 @@ async fn main() -> Result<()> {
912904
break;
913905
};
914906
if let Err(e) = r? {
915-
error!("{}", e);
907+
error!("{e}");
916908
}
917909
}
918910

casr/src/bin/casr-gdb.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ fn main() -> Result<()> {
259259
// Get crash line.
260260
if let Ok(crash_line) = parsed_stacktrace.crash_line() {
261261
report.crashline = crash_line.to_string();
262-
if let CrashLine::Source(debug) = crash_line {
263-
if let Some(sources) = CrashReport::sources(&debug) {
264-
report.source = sources;
265-
}
262+
if let CrashLine::Source(debug) = crash_line
263+
&& let Some(sources) = CrashReport::sources(&debug)
264+
{
265+
report.source = sources;
266266
}
267267
}
268268

casr/src/bin/casr-js.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ fn main() -> Result<()> {
181181
let stacktrace = JsStacktrace::parse_stacktrace(&report.stacktrace)?;
182182
if let Ok(crash_line) = stacktrace.crash_line() {
183183
report.crashline = crash_line.to_string();
184-
if let CrashLine::Source(debug) = crash_line {
185-
if let Some(sources) = CrashReport::sources(&debug) {
186-
report.source = sources;
187-
}
184+
if let CrashLine::Source(debug) = crash_line
185+
&& let Some(sources) = CrashReport::sources(&debug)
186+
{
187+
report.source = sources;
188188
}
189189
}
190190

casr/src/bin/casr-libfuzzer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,14 @@ fn main() -> Result<()> {
205205
let mut is_libafl_based = false;
206206
let crash_filter = if crash_files
207207
.iter()
208-
.any(|(fname, _)| fname.starts_with("crash-") || fname.starts_with("leak-"))
208+
.any(|(fname, _)| fname.ends_with(".metadata"))
209209
{
210+
is_libafl_based = true;
211+
|arg: &(&std::string::String, &PathBuf)| !arg.0.starts_with(".")
212+
} else {
210213
|arg: &(&std::string::String, &PathBuf)| {
211214
arg.0.starts_with("crash-") || arg.0.starts_with("leak-")
212215
}
213-
} else {
214-
is_libafl_based = true;
215-
|arg: &(&std::string::String, &PathBuf)| !arg.0.starts_with(".")
216216
};
217217

218218
// Get input file argument index.

casr/src/bin/casr-lua.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ fn main() -> Result<()> {
130130
// Create report.
131131
let mut report = CrashReport::new();
132132
report.executable_path = argv[0].to_string();
133-
if argv.len() > 1 {
134-
if let Some(fname) = Path::new(argv[0]).file_name() {
135-
let fname = fname.to_string_lossy();
136-
if fname.starts_with("lua") && !fname.ends_with(".lua") && argv[1].ends_with(".lua") {
137-
report.executable_path = argv[1].to_string();
138-
}
133+
if argv.len() > 1
134+
&& let Some(fname) = Path::new(argv[0]).file_name()
135+
{
136+
let fname = fname.to_string_lossy();
137+
if fname.starts_with("lua") && !fname.ends_with(".lua") && argv[1].ends_with(".lua") {
138+
report.executable_path = argv[1].to_string();
139139
}
140140
}
141+
141142
report.proc_cmdline = argv.join(" ");
142143
let _ = report.add_os_info();
143144
let _ = report.add_proc_environ();
@@ -153,10 +154,10 @@ fn main() -> Result<()> {
153154
report.execution_class = exception.severity()?;
154155
if let Ok(crashline) = exception.crash_line() {
155156
report.crashline = crashline.to_string();
156-
if let CrashLine::Source(debug) = crashline {
157-
if let Some(sources) = CrashReport::sources(&debug) {
158-
report.source = sources;
159-
}
157+
if let CrashLine::Source(debug) = crashline
158+
&& let Some(sources) = CrashReport::sources(&debug)
159+
{
160+
report.source = sources;
160161
}
161162
}
162163
let stacktrace = exception.parse_stacktrace()?;

casr/src/bin/casr-python.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ fn main() -> Result<()> {
130130
// Create report.
131131
let mut report = CrashReport::new();
132132
report.executable_path = argv[0].to_string();
133-
if argv.len() > 1 {
134-
if let Some(fname) = Path::new(argv[0]).file_name() {
135-
let fname = fname.to_string_lossy();
136-
if fname.starts_with("python") && !fname.ends_with(".py") && argv[1].ends_with(".py") {
137-
report.executable_path = argv[1].to_string();
138-
}
133+
if argv.len() > 1
134+
&& let Some(fname) = Path::new(argv[0]).file_name()
135+
{
136+
let fname = fname.to_string_lossy();
137+
if fname.starts_with("python") && !fname.ends_with(".py") && argv[1].ends_with(".py") {
138+
report.executable_path = argv[1].to_string();
139139
}
140140
}
141+
141142
report.proc_cmdline = argv.join(" ");
142143
let _ = report.add_os_info();
143144
let _ = report.add_proc_environ();
@@ -169,11 +170,10 @@ fn main() -> Result<()> {
169170
report.stacktrace =
170171
PythonStacktrace::extract_stacktrace(&report.python_report.join("\n"))?;
171172
// Get exception from python report.
172-
if report.python_report.len() > 1 {
173-
if let Some(exception) = PythonException::parse_exception(&report.python_report[1])
174-
{
175-
report.execution_class = exception;
176-
}
173+
if report.python_report.len() > 1
174+
&& let Some(exception) = PythonException::parse_exception(&report.python_report[1])
175+
{
176+
report.execution_class = exception;
177177
}
178178
} else {
179179
// Call casr-san
@@ -204,10 +204,10 @@ fn main() -> Result<()> {
204204
let stacktrace = PythonStacktrace::parse_stacktrace(&report.stacktrace)?;
205205
if let Ok(crash_line) = stacktrace.crash_line() {
206206
report.crashline = crash_line.to_string();
207-
if let CrashLine::Source(debug) = crash_line {
208-
if let Some(sources) = CrashReport::sources(&debug) {
209-
report.source = sources;
210-
}
207+
if let CrashLine::Source(debug) = crash_line
208+
&& let Some(sources) = CrashReport::sources(&debug)
209+
{
210+
report.source = sources;
211211
}
212212
}
213213

casr/src/bin/casr-san.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,10 @@ fn main() -> Result<()> {
332332
// Get crash line.
333333
if let Ok(crash_line) = stacktrace.crash_line() {
334334
report.crashline = crash_line.to_string();
335-
if let CrashLine::Source(debug) = crash_line {
336-
if let Some(sources) = CrashReport::sources(&debug) {
337-
report.source = sources;
338-
}
335+
if let CrashLine::Source(debug) = crash_line
336+
&& let Some(sources) = CrashReport::sources(&debug)
337+
{
338+
report.source = sources;
339339
}
340340
}
341341

0 commit comments

Comments
 (0)