From fe4e11a7627ce9a328001e734642042fbf565a6a Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Tue, 20 Jul 2021 20:07:25 -0400 Subject: [PATCH 1/5] verify `{input}` is used by target_env or target_options in coverage task --- src/agent/onefuzz-agent/src/local/coverage.rs | 1 + .../src/tasks/coverage/generic.rs | 23 ++++++++++++++++++- src/agent/onefuzz/src/expand.rs | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/agent/onefuzz-agent/src/local/coverage.rs b/src/agent/onefuzz-agent/src/local/coverage.rs index 920d092521..ea9fadc4aa 100644 --- a/src/agent/onefuzz-agent/src/local/coverage.rs +++ b/src/agent/onefuzz-agent/src/local/coverage.rs @@ -88,6 +88,7 @@ pub fn build_shared_args(local_job: bool) -> Vec> { .multiple(true), Arg::with_name(TARGET_OPTIONS) .long(TARGET_OPTIONS) + .default_value("{input}") .takes_value(true) .value_delimiter(" ") .help("Use a quoted string with space separation to denote multiple arguments"), diff --git a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs index 7124e427c0..d982959de3 100644 --- a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs @@ -12,7 +12,7 @@ use async_trait::async_trait; use coverage::block::CommandBlockCov; use coverage::cache::ModuleCache; use coverage::code::{CmdFilter, CmdFilterDef}; -use onefuzz::expand::Expand; +use onefuzz::expand::{Expand, PlaceHolder}; use onefuzz::syncdir::SyncedDir; use onefuzz_telemetry::{warn, Event::coverage_data, EventData}; use serde::de::DeserializeOwned; @@ -82,6 +82,10 @@ impl CoverageTask { let heartbeat = self.config.common.init_heartbeat(None).await?; let mut context = TaskContext::new(cache, &self.config, coverage, filter, heartbeat); + if !context.uses_input() { + bail!("input is not specified on the command line or arguments for the target"); + } + context.heartbeat.alive(); let mut seen_inputs = false; @@ -245,6 +249,23 @@ impl<'a> TaskContext<'a> { Ok(coverage) } + fn uses_input(&self) -> bool { + let input = PlaceHolder::Input.get_string(); + + for entry in &self.config.target_options { + if entry == &input { + return true; + } + } + for (k, v) in &self.config.target_env { + if k == &input || v == &input { + return true; + } + } + + false + } + fn command_for_input(&self, input: &Path) -> Result { let expand = Expand::new() .input_path(input) diff --git a/src/agent/onefuzz/src/expand.rs b/src/agent/onefuzz/src/expand.rs index a83a250a05..efe8518c27 100644 --- a/src/agent/onefuzz/src/expand.rs +++ b/src/agent/onefuzz/src/expand.rs @@ -48,7 +48,7 @@ pub enum PlaceHolder { } impl PlaceHolder { - fn get_string(&self) -> String { + pub fn get_string(&self) -> String { match self { Self::Input => "{input}", Self::Crashes => "{crashes}", From 5c790f1c805d6721dd37b725c51717b41b3dcbc7 Mon Sep 17 00:00:00 2001 From: bmc-msft <41130664+bmc-msft@users.noreply.github.com> Date: Wed, 21 Jul 2021 13:36:50 -0400 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Cheick Keita --- src/agent/onefuzz-agent/src/tasks/coverage/generic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs index d982959de3..16fce812ec 100644 --- a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs @@ -253,12 +253,12 @@ impl<'a> TaskContext<'a> { let input = PlaceHolder::Input.get_string(); for entry in &self.config.target_options { - if entry == &input { + if entry.contains(&input) { return true; } } for (k, v) in &self.config.target_env { - if k == &input || v == &input { + if k == &input || v.contains(&input) { return true; } } From 308209053dcc4e5047398b5cd9c9e7475cee6110 Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Wed, 21 Jul 2021 13:38:09 -0400 Subject: [PATCH 3/5] add unit test to verify placeholder in larger string works --- src/agent/onefuzz/src/expand.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/agent/onefuzz/src/expand.rs b/src/agent/onefuzz/src/expand.rs index efe8518c27..92397b17e1 100644 --- a/src/agent/onefuzz/src/expand.rs +++ b/src/agent/onefuzz/src/expand.rs @@ -469,4 +469,11 @@ mod tests { Ok(()) } + + #[test] + fn test_expand_in_string() -> Result<()> { + let result = Expand::new().input_path("src/lib.rs").evaluate_value("a {input} b")?; + assert!(result.contains("src/lib.rs")); + Ok(()) + } } From abe8d920adf93f82fe77e485d1118c445f939d20 Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Wed, 21 Jul 2021 13:41:53 -0400 Subject: [PATCH 4/5] fmt --- src/agent/onefuzz/src/expand.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/agent/onefuzz/src/expand.rs b/src/agent/onefuzz/src/expand.rs index 92397b17e1..a9f9d823db 100644 --- a/src/agent/onefuzz/src/expand.rs +++ b/src/agent/onefuzz/src/expand.rs @@ -472,7 +472,9 @@ mod tests { #[test] fn test_expand_in_string() -> Result<()> { - let result = Expand::new().input_path("src/lib.rs").evaluate_value("a {input} b")?; + let result = Expand::new() + .input_path("src/lib.rs") + .evaluate_value("a {input} b")?; assert!(result.contains("src/lib.rs")); Ok(()) } From 6a488e2d73e7bbc6337a7b774510335ded52b7ae Mon Sep 17 00:00:00 2001 From: bmc-msft <41130664+bmc-msft@users.noreply.github.com> Date: Wed, 21 Jul 2021 13:59:11 -0400 Subject: [PATCH 5/5] Apply suggestions from code review --- src/agent/onefuzz/src/expand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/onefuzz/src/expand.rs b/src/agent/onefuzz/src/expand.rs index a9f9d823db..6e02c9d5dc 100644 --- a/src/agent/onefuzz/src/expand.rs +++ b/src/agent/onefuzz/src/expand.rs @@ -475,7 +475,7 @@ mod tests { let result = Expand::new() .input_path("src/lib.rs") .evaluate_value("a {input} b")?; - assert!(result.contains("src/lib.rs")); + assert!(result.contains("lib.rs")); Ok(()) } }