mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 20:38:06 +00:00
adding {setup_dir} to variable expansion (#417)
## Summary of the Pull Request Adds a new placeholder {setup_dir} for the setup directory ## PR Checklist * [x] Applies to work item: #221 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/onefuzz) and sign the CLI. * [x] Requires documentation to be updated * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Info on Pull Request _What does this include?_ ## Validation Steps Performed _How does someone test & validate?_
This commit is contained in:
@ -29,6 +29,7 @@ async fn run_impl(input: String, config: Config) -> Result<()> {
|
||||
|
||||
pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
let target_exe = value_t!(args, "target_exe", PathBuf)?;
|
||||
let setup_dir = value_t!(args, "setup_dir", PathBuf)?;
|
||||
let input = value_t!(args, "input", String)?;
|
||||
let target_timeout = value_t!(args, "target_timeout", u64).ok();
|
||||
let check_retry_count = value_t!(args, "check_retry_count", u64)?;
|
||||
@ -65,6 +66,7 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
job_id: Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap(),
|
||||
task_id: Uuid::parse_str("11111111-1111-1111-1111-111111111111").unwrap(),
|
||||
instance_id: Uuid::parse_str("22222222-2222-2222-2222-222222222222").unwrap(),
|
||||
setup_dir,
|
||||
},
|
||||
};
|
||||
|
||||
@ -77,6 +79,11 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
pub fn args() -> App<'static, 'static> {
|
||||
SubCommand::with_name("generic-crash-report")
|
||||
.about("execute a local-only generic crash report")
|
||||
.arg(
|
||||
Arg::with_name("setup_dir")
|
||||
.takes_value(true)
|
||||
.required(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("target_exe")
|
||||
.takes_value(true)
|
||||
|
@ -38,6 +38,7 @@ async fn run_impl(input: String, config: Config) -> Result<()> {
|
||||
|
||||
pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
let target_exe = value_t!(args, "target_exe", PathBuf)?;
|
||||
let setup_dir = value_t!(args, "setup_dir", PathBuf)?;
|
||||
let input = value_t!(args, "input", String)?;
|
||||
let result_dir = value_t!(args, "result_dir", String)?;
|
||||
let target_options = args.values_of_lossy("target_options").unwrap_or_default();
|
||||
@ -69,6 +70,7 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
job_id: Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap(),
|
||||
task_id: Uuid::parse_str("11111111-1111-1111-1111-111111111111").unwrap(),
|
||||
instance_id: Uuid::parse_str("22222222-2222-2222-2222-222222222222").unwrap(),
|
||||
setup_dir,
|
||||
},
|
||||
};
|
||||
|
||||
@ -81,6 +83,11 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
pub fn args() -> App<'static, 'static> {
|
||||
SubCommand::with_name("libfuzzer-coverage")
|
||||
.about("execute a local-only libfuzzer coverage task")
|
||||
.arg(
|
||||
Arg::with_name("setup_dir")
|
||||
.takes_value(true)
|
||||
.required(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("target_exe")
|
||||
.takes_value(true)
|
||||
|
@ -30,6 +30,7 @@ async fn run_impl(input: String, config: Config) -> Result<()> {
|
||||
|
||||
pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
let target_exe = value_t!(args, "target_exe", PathBuf)?;
|
||||
let setup_dir = value_t!(args, "setup_dir", PathBuf)?;
|
||||
let input = value_t!(args, "input", String)?;
|
||||
let target_options = args.values_of_lossy("target_options").unwrap_or_default();
|
||||
let mut target_env = HashMap::new();
|
||||
@ -65,6 +66,7 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
job_id: Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap(),
|
||||
task_id: Uuid::parse_str("11111111-1111-1111-1111-111111111111").unwrap(),
|
||||
instance_id: Uuid::parse_str("22222222-2222-2222-2222-222222222222").unwrap(),
|
||||
setup_dir,
|
||||
},
|
||||
};
|
||||
|
||||
@ -77,6 +79,11 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
pub fn args() -> App<'static, 'static> {
|
||||
SubCommand::with_name("libfuzzer-crash-report")
|
||||
.about("execute a local-only libfuzzer crash report task")
|
||||
.arg(
|
||||
Arg::with_name("setup_dir")
|
||||
.takes_value(true)
|
||||
.required(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("target_exe")
|
||||
.takes_value(true)
|
||||
|
@ -25,6 +25,7 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
let crashes_dir = value_t!(args, "crashes_dir", String)?;
|
||||
let inputs_dir = value_t!(args, "inputs_dir", String)?;
|
||||
let target_exe = value_t!(args, "target_exe", PathBuf)?;
|
||||
let setup_dir = value_t!(args, "setup_dir", PathBuf)?;
|
||||
let target_options = args.values_of_lossy("target_options").unwrap_or_default();
|
||||
|
||||
// this happens during setup, not during runtime
|
||||
@ -71,6 +72,7 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
job_id: Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap(),
|
||||
task_id: Uuid::parse_str("11111111-1111-1111-1111-111111111111").unwrap(),
|
||||
instance_id: Uuid::parse_str("22222222-2222-2222-2222-222222222222").unwrap(),
|
||||
setup_dir,
|
||||
},
|
||||
};
|
||||
|
||||
@ -83,6 +85,11 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
pub fn args() -> App<'static, 'static> {
|
||||
SubCommand::with_name("libfuzzer-fuzz")
|
||||
.about("execute a local-only libfuzzer crash report task")
|
||||
.arg(
|
||||
Arg::with_name("setup_dir")
|
||||
.takes_value(true)
|
||||
.required(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("target_exe")
|
||||
.takes_value(true)
|
||||
|
@ -16,6 +16,7 @@ use uuid::Uuid;
|
||||
|
||||
pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
let target_exe = value_t!(args, "target_exe", PathBuf)?;
|
||||
let setup_dir = value_t!(args, "setup_dir", PathBuf)?;
|
||||
let inputs = value_t!(args, "inputs", String)?;
|
||||
let unique_inputs = value_t!(args, "unique_inputs", String)?;
|
||||
let target_options = args.values_of_lossy("target_options").unwrap_or_default();
|
||||
@ -50,6 +51,7 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
job_id: Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap(),
|
||||
task_id: Uuid::parse_str("11111111-1111-1111-1111-111111111111").unwrap(),
|
||||
instance_id: Uuid::parse_str("22222222-2222-2222-2222-222222222222").unwrap(),
|
||||
setup_dir,
|
||||
},
|
||||
preserve_existing_outputs: true,
|
||||
});
|
||||
@ -66,6 +68,11 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
|
||||
pub fn args() -> App<'static, 'static> {
|
||||
SubCommand::with_name("libfuzzer-merge")
|
||||
.about("execute a local-only libfuzzer merge task")
|
||||
.arg(
|
||||
Arg::with_name("setup_dir")
|
||||
.takes_value(true)
|
||||
.required(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("target_exe")
|
||||
.takes_value(true)
|
||||
|
@ -39,6 +39,12 @@ fn main() -> Result<()> {
|
||||
.short("c")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("setup_dir")
|
||||
.long("setup_dir")
|
||||
.short("s")
|
||||
.takes_value(true),
|
||||
)
|
||||
.subcommand(debug::cmd::args())
|
||||
.subcommand(SubCommand::with_name("licenses").about("display third-party licenses"));
|
||||
|
||||
@ -58,7 +64,8 @@ fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
let config_path: PathBuf = matches.value_of("config").unwrap().parse()?;
|
||||
let config = Config::from_file(config_path)?;
|
||||
let setup_dir = matches.value_of("setup_dir");
|
||||
let config = Config::from_file(config_path, setup_dir)?;
|
||||
|
||||
init_telemetry(&config);
|
||||
|
||||
|
@ -121,7 +121,8 @@ pub async fn run_tool(input: impl AsRef<Path>, config: &Config) -> Result<()> {
|
||||
.target_options(&config.target_options)
|
||||
.analyzer_exe(&config.analyzer_exe)
|
||||
.analyzer_options(&config.analyzer_options)
|
||||
.output_dir(&config.analysis.path);
|
||||
.output_dir(&config.analysis.path)
|
||||
.setup_dir(&config.common.setup_dir);
|
||||
|
||||
let analyzer_path = Expand::new()
|
||||
.tools_dir(&config.tools.path)
|
||||
|
@ -10,7 +10,7 @@ use onefuzz::{
|
||||
};
|
||||
use reqwest::Url;
|
||||
use serde::{self, Deserialize};
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
@ -33,6 +33,8 @@ pub struct CommonConfig {
|
||||
pub heartbeat_queue: Option<Url>,
|
||||
|
||||
pub telemetry_key: Option<Uuid>,
|
||||
|
||||
pub setup_dir: PathBuf,
|
||||
}
|
||||
|
||||
impl CommonConfig {
|
||||
@ -79,9 +81,16 @@ pub enum Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_file(path: impl AsRef<Path>) -> Result<Self> {
|
||||
pub fn from_file(path: impl AsRef<Path>, setup_dir: Option<impl AsRef<Path>>) -> Result<Self> {
|
||||
let json = std::fs::read_to_string(path)?;
|
||||
Ok(serde_json::from_str(&json)?)
|
||||
let mut json_config: serde_json::Value = serde_json::from_str(&json)?;
|
||||
// override the setup_dir in the config file with the parameter value if specified
|
||||
if let Some(setup_dir) = setup_dir {
|
||||
json_config["setup_dir"] =
|
||||
serde_json::Value::String(setup_dir.as_ref().to_string_lossy().into());
|
||||
}
|
||||
|
||||
Ok(serde_json::from_value(json_config)?)
|
||||
}
|
||||
|
||||
pub fn common(&self) -> &CommonConfig {
|
||||
|
@ -104,6 +104,7 @@ impl CoverageTask {
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
target.check_help().await?;
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ pub async fn spawn(config: Arc<GeneratorConfig>) -> Result<(), Error> {
|
||||
let sync_task = continuous_sync(&config.readonly_inputs, Pull, config.ensemble_sync_delay);
|
||||
let crash_dir_monitor = config.crashes.monitor_results(new_result);
|
||||
let tester = Tester::new(
|
||||
&config.common.setup_dir,
|
||||
&config.target_exe,
|
||||
&config.target_options,
|
||||
&config.target_env,
|
||||
|
@ -72,6 +72,7 @@ impl LibFuzzerFuzzTask {
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
target.check_help().await?;
|
||||
}
|
||||
@ -156,6 +157,7 @@ impl LibFuzzerFuzzTask {
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
let mut running = fuzzer.fuzz(crash_dir.path(), local_inputs, &inputs)?;
|
||||
|
||||
|
@ -102,6 +102,7 @@ pub async fn spawn(config: SupervisorConfig) -> Result<(), Error> {
|
||||
&config.supervisor_options,
|
||||
&config.supervisor_env,
|
||||
&config.supervisor_input_marker,
|
||||
&config.common.setup_dir,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -156,6 +157,7 @@ async fn start_supervisor(
|
||||
supervisor_options: &[String],
|
||||
supervisor_env: &HashMap<String, String>,
|
||||
supervisor_input_marker: &Option<String>,
|
||||
setup_dir: impl AsRef<Path>,
|
||||
) -> Result<Child> {
|
||||
let mut cmd = Command::new(supervisor_path.as_ref());
|
||||
|
||||
@ -173,7 +175,8 @@ async fn start_supervisor(
|
||||
.runtime_dir(runtime_dir)
|
||||
.target_exe(target_exe)
|
||||
.target_options(target_options)
|
||||
.input_corpus(inputs_dir);
|
||||
.input_corpus(inputs_dir)
|
||||
.setup_dir(setup_dir);
|
||||
|
||||
if let Some(input_marker) = supervisor_input_marker {
|
||||
expand.input_marker(input_marker);
|
||||
@ -276,6 +279,7 @@ mod tests {
|
||||
&supervisor_options,
|
||||
&supervisor_env,
|
||||
&supervisor_input_marker,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -138,7 +138,8 @@ async fn merge(config: &Config, output_dir: impl AsRef<Path>) -> Result<()> {
|
||||
.supervisor_exe(&config.supervisor_exe)
|
||||
.supervisor_options(&config.supervisor_options)
|
||||
.generated_inputs(output_dir)
|
||||
.target_exe(&config.target_exe);
|
||||
.target_exe(&config.target_exe)
|
||||
.setup_dir(&config.common.setup_dir);
|
||||
|
||||
if config.target_options_merge {
|
||||
supervisor_args.target_options(&config.target_options);
|
||||
|
@ -52,6 +52,7 @@ pub async fn spawn(config: Arc<Config>) -> Result<()> {
|
||||
&config.target_exe,
|
||||
&config.target_options,
|
||||
&config.target_env,
|
||||
&config.common.setup_dir,
|
||||
);
|
||||
target.check_help().await?;
|
||||
}
|
||||
@ -162,6 +163,7 @@ pub async fn merge_inputs(
|
||||
&config.target_exe,
|
||||
&config.target_options,
|
||||
&config.target_env,
|
||||
&config.common.setup_dir,
|
||||
);
|
||||
merger.merge(&config.unique_inputs.path, &candidates).await
|
||||
}
|
||||
|
@ -87,6 +87,7 @@ pub struct GenericReportProcessor<'a> {
|
||||
impl<'a> GenericReportProcessor<'a> {
|
||||
pub fn new(config: &'a Config, heartbeat_client: Option<TaskHeartbeatClient>) -> Self {
|
||||
let tester = Tester::new(
|
||||
&config.common.setup_dir,
|
||||
&config.target_exe,
|
||||
&config.target_options,
|
||||
&config.target_env,
|
||||
|
@ -61,6 +61,7 @@ impl ReportTask {
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
target.check_help().await?;
|
||||
}
|
||||
@ -101,6 +102,7 @@ impl AsanProcessor {
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
|
||||
let task_id = self.config.common.task_id;
|
||||
|
Reference in New Issue
Block a user