From 94e29047d7954035012898b4f0797452682d7f46 Mon Sep 17 00:00:00 2001 From: Noah McGregor Harper <74685766+nharper285@users.noreply.github.com> Date: Fri, 10 Dec 2021 14:32:44 -0800 Subject: [PATCH] Fixing agent code. (#1516) * Fixing agent code. * Update src/agent/stacktrace-parser/src/lib.rs Co-authored-by: Cheick Keita * Update src/agent/stacktrace-parser/src/lib.rs Co-authored-by: Cheick Keita * Formatting lib.rs * Adding additional fix. * Correct regex fix. * Fixing var names. * working to remove more clippy issues. * Removing clippy and adding allows. * Fixing tag for dead code * Trying to figure out issue. * Fixing jobs.rs. * Adding tag. * Running into syntax errors. * Adding newline. * Trying to add tag correctly. * Another windows clippy fix. * Adding allow tag to struct that appears used. Co-authored-by: nharper285 Co-authored-by: Cheick Keita --- src/agent/coverage/src/block/pe_provider.rs | 2 +- src/agent/input-tester/src/logging.rs | 1 + src/agent/onefuzz-agent/src/local/tui.rs | 1 + src/agent/onefuzz-agent/src/tasks/merge/generic.rs | 7 ------- .../onefuzz-agent/src/tasks/merge/libfuzzer_merge.rs | 6 ------ src/agent/onefuzz-agent/src/tasks/report/crash_report.rs | 8 ++++---- src/agent/onefuzz-agent/src/tasks/report/generic.rs | 4 ++-- .../onefuzz-agent/src/tasks/report/libfuzzer_report.rs | 4 ++-- src/agent/onefuzz/src/auth.rs | 1 + src/agent/srcview/src/report.rs | 4 ++-- src/agent/stacktrace-parser/src/lib.rs | 6 +++--- src/agent/win-util/src/jobs.rs | 1 + 12 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/agent/coverage/src/block/pe_provider.rs b/src/agent/coverage/src/block/pe_provider.rs index baa5f0e625..5fca3f7a03 100644 --- a/src/agent/coverage/src/block/pe_provider.rs +++ b/src/agent/coverage/src/block/pe_provider.rs @@ -73,7 +73,7 @@ where // reverse the instrumented basic blocks. fn provide_from_inline_table(&mut self, inline_table: SancovTable) -> Result> { let mut visitor = - SancovInlineAccessVisitor::new(inline_table, self.data, self.pe, &mut self.pdb)?; + SancovInlineAccessVisitor::new(inline_table, self.data, self.pe, self.pdb)?; let debug_info = self.pdb.debug_information()?; let mut modules = debug_info.modules()?; diff --git a/src/agent/input-tester/src/logging.rs b/src/agent/input-tester/src/logging.rs index e221d83800..bc18631540 100644 --- a/src/agent/input-tester/src/logging.rs +++ b/src/agent/input-tester/src/logging.rs @@ -28,6 +28,7 @@ where } #[derive(Debug)] +#[allow(dead_code)] pub struct ProcessDetails<'a> { pid: u32, output: &'a Output, diff --git a/src/agent/onefuzz-agent/src/local/tui.rs b/src/agent/onefuzz-agent/src/local/tui.rs index 3d09bcd7a5..b3aded4dc8 100644 --- a/src/agent/onefuzz-agent/src/local/tui.rs +++ b/src/agent/onefuzz-agent/src/local/tui.rs @@ -68,6 +68,7 @@ const FILE_MONITOR_POLLING_PERIOD: Duration = Duration::from_secs(5); const EVENT_POLLING_PERIOD: Duration = Duration::from_secs(1); #[derive(Debug, Default)] +#[allow(dead_code)] struct CoverageData { covered: Option, features: Option, diff --git a/src/agent/onefuzz-agent/src/tasks/merge/generic.rs b/src/agent/onefuzz-agent/src/tasks/merge/generic.rs index afaa0df433..cbf4da48e0 100644 --- a/src/agent/onefuzz-agent/src/tasks/merge/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/merge/generic.rs @@ -19,13 +19,6 @@ use std::{ use storage_queue::{QueueClient, EMPTY_QUEUE_DELAY}; use tokio::process::Command; -#[derive(Debug, Deserialize)] -struct QueueMessage { - content_length: u32, - - url: Url, -} - #[derive(Debug, Deserialize)] pub struct Config { pub supervisor_exe: String, diff --git a/src/agent/onefuzz-agent/src/tasks/merge/libfuzzer_merge.rs b/src/agent/onefuzz-agent/src/tasks/merge/libfuzzer_merge.rs index 3616f0d86a..b5972dc3c9 100644 --- a/src/agent/onefuzz-agent/src/tasks/merge/libfuzzer_merge.rs +++ b/src/agent/onefuzz-agent/src/tasks/merge/libfuzzer_merge.rs @@ -23,12 +23,6 @@ use std::{ }; use storage_queue::{QueueClient, EMPTY_QUEUE_DELAY}; -#[derive(Debug, Deserialize)] -struct QueueMessage { - content_length: u32, - url: Url, -} - #[derive(Debug, Deserialize)] pub struct Config { pub target_exe: PathBuf, diff --git a/src/agent/onefuzz-agent/src/tasks/report/crash_report.rs b/src/agent/onefuzz-agent/src/tasks/report/crash_report.rs index ed07e81e70..39fa418d0c 100644 --- a/src/agent/onefuzz-agent/src/tasks/report/crash_report.rs +++ b/src/agent/onefuzz-agent/src/tasks/report/crash_report.rs @@ -75,8 +75,8 @@ pub struct NoCrash { #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum CrashTestResult { - CrashReport(CrashReport), - NoRepro(NoCrash), + CrashReport(Box), + NoRepro(Box), } #[derive(Debug, Deserialize, Serialize)] @@ -268,13 +268,13 @@ pub async fn parse_report_file(path: PathBuf) -> Result { let report: Result = serde_json::from_value(json.clone()); let report_err = match report { - Ok(report) => return Ok(CrashTestResult::CrashReport(report)), + Ok(report) => return Ok(CrashTestResult::CrashReport(Box::new(report))), Err(err) => err, }; let no_repro: Result = serde_json::from_value(json); let no_repro_err = match no_repro { - Ok(no_repro) => return Ok(CrashTestResult::NoRepro(no_repro)), + Ok(no_repro) => return Ok(CrashTestResult::NoRepro(Box::new(no_repro))), Err(err) => err, }; diff --git a/src/agent/onefuzz-agent/src/tasks/report/generic.rs b/src/agent/onefuzz-agent/src/tasks/report/generic.rs index 237d888777..61e41e63d2 100644 --- a/src/agent/onefuzz-agent/src/tasks/report/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/report/generic.rs @@ -152,7 +152,7 @@ pub async fn test_input(args: TestInputArgs<'_>) -> Result { input_sha256, args.minimized_stack_depth, ); - Ok(CrashTestResult::CrashReport(crash_report)) + Ok(CrashTestResult::CrashReport(Box::new(crash_report))) } else { let no_repro = NoCrash { input_blob, @@ -164,7 +164,7 @@ pub async fn test_input(args: TestInputArgs<'_>) -> Result { error: test_report.error.map(|e| format!("{}", e)), }; - Ok(CrashTestResult::NoRepro(no_repro)) + Ok(CrashTestResult::NoRepro(Box::new(no_repro))) } } diff --git a/src/agent/onefuzz-agent/src/tasks/report/libfuzzer_report.rs b/src/agent/onefuzz-agent/src/tasks/report/libfuzzer_report.rs index 42f6784db1..1e1e779eb8 100644 --- a/src/agent/onefuzz-agent/src/tasks/report/libfuzzer_report.rs +++ b/src/agent/onefuzz-agent/src/tasks/report/libfuzzer_report.rs @@ -150,7 +150,7 @@ pub async fn test_input(args: TestInputArgs<'_>) -> Result { input_sha256, args.minimized_stack_depth, ); - Ok(CrashTestResult::CrashReport(crash_report)) + Ok(CrashTestResult::CrashReport(Box::new(crash_report))) } None => { let no_repro = NoCrash { @@ -163,7 +163,7 @@ pub async fn test_input(args: TestInputArgs<'_>) -> Result { error: test_report.error.map(|e| format!("{}", e)), }; - Ok(CrashTestResult::NoRepro(no_repro)) + Ok(CrashTestResult::NoRepro(Box::new(no_repro))) } } } diff --git a/src/agent/onefuzz/src/auth.rs b/src/agent/onefuzz/src/auth.rs index c58383f363..19a9b08d66 100644 --- a/src/agent/onefuzz/src/auth.rs +++ b/src/agent/onefuzz/src/auth.rs @@ -233,6 +233,7 @@ impl ManagedIdentityCredentials { // #get-an-access-token-using-the-vms-system-assigned-managed-identity // -and-use-it-to-call-resource-manager #[derive(Clone, Debug, Deserialize)] +#[allow(dead_code)] struct ManagedIdentityAccessTokenBody { access_token: Secret, resource: String, diff --git a/src/agent/srcview/src/report.rs b/src/agent/srcview/src/report.rs index f08383d138..c29a557a36 100644 --- a/src/agent/srcview/src/report.rs +++ b/src/agent/srcview/src/report.rs @@ -82,7 +82,7 @@ impl Report { srcview: &SrcView, include_regex: Option<&str>, ) -> Result { - let include = include_regex.map(|f| Regex::new(f)).transpose()?; + let include = include_regex.map(Regex::new).transpose()?; let filecov = Self::compute_filecov(coverage, srcview, &include)?; // should this function take &[ModOff] and perform the conversion itself? @@ -352,7 +352,7 @@ impl Report { /// println!("{}", xml); /// ``` pub fn cobertura(&self, filter_regex: Option<&str>) -> Result { - let filter = filter_regex.map(|f| Regex::new(f)).transpose()?; + let filter = filter_regex.map(Regex::new).transpose()?; let mut backing: Vec = Vec::new(); let mut ew = EmitterConfig::new() diff --git a/src/agent/stacktrace-parser/src/lib.rs b/src/agent/stacktrace-parser/src/lib.rs index 19a97b49fb..6e4fdc4783 100644 --- a/src/agent/stacktrace-parser/src/lib.rs +++ b/src/agent/stacktrace-parser/src/lib.rs @@ -117,9 +117,9 @@ fn function_without_args(func: &str) -> String { // with ClusterFuzz, this is going to stay this way for now. This is used to // fill in `minimized_stack_functions_names`. The unstripped version will be // in `minimized_stack`. - func.splitn(2, '(') - .next() - .expect("splitn should always return at least one item") + func.split_once('(') + .map(|(x, _)| x) + .unwrap_or(func) .to_string() } diff --git a/src/agent/win-util/src/jobs.rs b/src/agent/win-util/src/jobs.rs index 8d8c15ccea..f5320f996d 100644 --- a/src/agent/win-util/src/jobs.rs +++ b/src/agent/win-util/src/jobs.rs @@ -446,6 +446,7 @@ impl JobInformation { } #[derive(Debug)] +#[allow(dead_code)] pub struct JobObjectLimitNotification { io_read_bytes_limit: Option, io_write_bytes_limit: Option,