Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Only keep coverage, libfuzzer and template commands (#3428)
Browse files Browse the repository at this point in the history
* Only keep coverage, libfuzzer and template commands

* Remove unused code
  • Loading branch information
tevoinea authored Aug 21, 2023
1 parent c0c5b83 commit a551709
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 1,217 deletions.
42 changes: 1 addition & 41 deletions src/agent/onefuzz-task/src/local/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

#[cfg(any(target_os = "linux", target_os = "windows"))]
use crate::local::coverage;
use crate::local::{
common::add_common_config, generic_analysis, generic_crash_report, generic_generator,
libfuzzer, libfuzzer_crash_report, libfuzzer_fuzz, libfuzzer_merge, libfuzzer_regression,
libfuzzer_test_input, radamsa, test_input, tui::TerminalUi,
};
use crate::local::{common::add_common_config, libfuzzer_fuzz, tui::TerminalUi};
use anyhow::{Context, Result};
use clap::{Arg, ArgAction, Command};
use std::time::Duration;
Expand All @@ -21,19 +17,9 @@ use super::template;
#[derive(Debug, PartialEq, Eq, EnumString, IntoStaticStr, EnumIter)]
#[strum(serialize_all = "kebab-case")]
enum Commands {
Radamsa,
#[cfg(any(target_os = "linux", target_os = "windows"))]
Coverage,
LibfuzzerFuzz,
LibfuzzerMerge,
LibfuzzerCrashReport,
LibfuzzerTestInput,
LibfuzzerRegression,
Libfuzzer,
CrashReport,
Generator,
Analysis,
TestInput,
Template,
}

Expand Down Expand Up @@ -68,23 +54,7 @@ pub async fn run(args: clap::ArgMatches) -> Result<()> {
match command {
#[cfg(any(target_os = "linux", target_os = "windows"))]
Commands::Coverage => coverage::run(&sub_args, event_sender).await,
Commands::Radamsa => radamsa::run(&sub_args, event_sender).await,
Commands::LibfuzzerCrashReport => {
libfuzzer_crash_report::run(&sub_args, event_sender).await
}
Commands::LibfuzzerFuzz => libfuzzer_fuzz::run(&sub_args, event_sender).await,
Commands::LibfuzzerMerge => libfuzzer_merge::run(&sub_args, event_sender).await,
Commands::LibfuzzerTestInput => {
libfuzzer_test_input::run(&sub_args, event_sender).await
}
Commands::LibfuzzerRegression => {
libfuzzer_regression::run(&sub_args, event_sender).await
}
Commands::Libfuzzer => libfuzzer::run(&sub_args, event_sender).await,
Commands::CrashReport => generic_crash_report::run(&sub_args, event_sender).await,
Commands::Generator => generic_generator::run(&sub_args, event_sender).await,
Commands::Analysis => generic_analysis::run(&sub_args, event_sender).await,
Commands::TestInput => test_input::run(&sub_args, event_sender).await,
Commands::Template => {
let config = sub_args
.get_one::<PathBuf>("config")
Expand Down Expand Up @@ -140,17 +110,7 @@ pub fn args(name: &'static str) -> Command {
let app = match subcommand {
#[cfg(any(target_os = "linux", target_os = "windows"))]
Commands::Coverage => coverage::args(subcommand.into()),
Commands::Radamsa => radamsa::args(subcommand.into()),
Commands::LibfuzzerCrashReport => libfuzzer_crash_report::args(subcommand.into()),
Commands::LibfuzzerFuzz => libfuzzer_fuzz::args(subcommand.into()),
Commands::LibfuzzerMerge => libfuzzer_merge::args(subcommand.into()),
Commands::LibfuzzerTestInput => libfuzzer_test_input::args(subcommand.into()),
Commands::LibfuzzerRegression => libfuzzer_regression::args(subcommand.into()),
Commands::Libfuzzer => libfuzzer::args(subcommand.into()),
Commands::CrashReport => generic_crash_report::args(subcommand.into()),
Commands::Generator => generic_generator::args(subcommand.into()),
Commands::Analysis => generic_analysis::args(subcommand.into()),
Commands::TestInput => test_input::args(subcommand.into()),
Commands::Template => Command::new("template")
.about("uses the template to generate a run")
.args(vec![Arg::new("config")
Expand Down
25 changes: 0 additions & 25 deletions src/agent/onefuzz-task/src/local/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,17 @@ pub const INPUTS_DIR: &str = "inputs_dir";
pub const CRASHES_DIR: &str = "crashes_dir";
pub const CRASHDUMPS_DIR: &str = "crashdumps_dir";
pub const TARGET_WORKERS: &str = "target_workers";
pub const REPORTS_DIR: &str = "reports_dir";
pub const NO_REPRO_DIR: &str = "no_repro_dir";
pub const TARGET_TIMEOUT: &str = "target_timeout";
pub const CHECK_RETRY_COUNT: &str = "check_retry_count";
pub const DISABLE_CHECK_QUEUE: &str = "disable_check_queue";
pub const UNIQUE_REPORTS_DIR: &str = "unique_reports_dir";
pub const COVERAGE_DIR: &str = "coverage_dir";
pub const READONLY_INPUTS: &str = "readonly_inputs_dir";
pub const CHECK_ASAN_LOG: &str = "check_asan_log";
pub const TOOLS_DIR: &str = "tools_dir";
pub const RENAME_OUTPUT: &str = "rename_output";
pub const CHECK_FUZZER_HELP: &str = "check_fuzzer_help";
pub const DISABLE_CHECK_DEBUGGER: &str = "disable_check_debugger";
pub const REGRESSION_REPORTS_DIR: &str = "regression_reports_dir";

pub const TARGET_EXE: &str = "target_exe";
pub const TARGET_ENV: &str = "target_env";
pub const TARGET_OPTIONS: &str = "target_options";
// pub const SUPERVISOR_EXE: &str = "supervisor_exe";
// pub const SUPERVISOR_ENV: &str = "supervisor_env";
// pub const SUPERVISOR_OPTIONS: &str = "supervisor_options";
pub const GENERATOR_EXE: &str = "generator_exe";
pub const GENERATOR_ENV: &str = "generator_env";
pub const GENERATOR_OPTIONS: &str = "generator_options";

pub const ANALYZER_EXE: &str = "analyzer_exe";
pub const ANALYZER_OPTIONS: &str = "analyzer_options";
pub const ANALYZER_ENV: &str = "analyzer_env";
pub const ANALYSIS_DIR: &str = "analysis_dir";
pub const ANALYSIS_INPUTS: &str = "analysis_inputs";
pub const ANALYSIS_UNIQUE_INPUTS: &str = "analysis_unique_inputs";
pub const PRESERVE_EXISTING_OUTPUTS: &str = "preserve_existing_outputs";

pub const CREATE_JOB_DIR: &str = "create_job_dir";

Expand All @@ -66,7 +45,6 @@ const WAIT_FOR_DIR_DELAY: Duration = Duration::from_secs(1);

pub enum CmdType {
Target,
Generator,
// Supervisor,
}

Expand All @@ -90,7 +68,6 @@ pub fn get_cmd_exe(cmd_type: CmdType, args: &clap::ArgMatches) -> Result<String>
let name = match cmd_type {
CmdType::Target => TARGET_EXE,
// CmdType::Supervisor => SUPERVISOR_EXE,
CmdType::Generator => GENERATOR_EXE,
};

args.get_one::<String>(name)
Expand All @@ -102,7 +79,6 @@ pub fn get_cmd_arg(cmd_type: CmdType, args: &clap::ArgMatches) -> Vec<String> {
let name = match cmd_type {
CmdType::Target => TARGET_OPTIONS,
// CmdType::Supervisor => SUPERVISOR_OPTIONS,
CmdType::Generator => GENERATOR_OPTIONS,
};

args.get_many::<String>(name)
Expand All @@ -115,7 +91,6 @@ pub fn get_cmd_env(cmd_type: CmdType, args: &clap::ArgMatches) -> Result<HashMap
let env_name = match cmd_type {
CmdType::Target => TARGET_ENV,
// CmdType::Supervisor => SUPERVISOR_ENV,
CmdType::Generator => GENERATOR_ENV,
};
get_hash_map(args, env_name)
}
Expand Down
128 changes: 1 addition & 127 deletions src/agent/onefuzz-task/src/local/generic_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,139 +3,13 @@

use std::{collections::HashMap, path::PathBuf};

use crate::{
local::common::{
build_local_context, get_cmd_arg, get_cmd_exe, get_hash_map, get_synced_dir, CmdType,
SyncCountDirMonitor, UiEvent, ANALYSIS_DIR, ANALYZER_ENV, ANALYZER_EXE, ANALYZER_OPTIONS,
CRASHES_DIR, NO_REPRO_DIR, REPORTS_DIR, TARGET_ENV, TARGET_EXE, TARGET_OPTIONS, TOOLS_DIR,
UNIQUE_REPORTS_DIR,
},
tasks::{
analysis::generic::{run as run_analysis, Config},
config::CommonConfig,
},
};
use crate::tasks::config::CommonConfig;
use anyhow::Result;
use async_trait::async_trait;
use clap::{Arg, Command};
use flume::Sender;
use schemars::JsonSchema;
use storage_queue::QueueClient;

use super::template::{RunContext, Template};

pub fn build_analysis_config(
args: &clap::ArgMatches,
input_queue: Option<QueueClient>,
common: CommonConfig,
event_sender: Option<Sender<UiEvent>>,
) -> Result<Config> {
let target_exe = get_cmd_exe(CmdType::Target, args)?.into();
let target_options = get_cmd_arg(CmdType::Target, args);

let analyzer_exe = args
.get_one::<String>(ANALYZER_EXE)
.cloned()
.ok_or_else(|| format_err!("expected {ANALYZER_EXE}"))?;

let analyzer_options = args
.get_many::<String>(ANALYZER_OPTIONS)
.unwrap_or_default()
.map(|x| x.to_string())
.collect();

let analyzer_env = get_hash_map(args, ANALYZER_ENV)?;
let analysis = get_synced_dir(ANALYSIS_DIR, common.job_id, common.task_id, args)?
.monitor_count(&event_sender)?;
let tools = get_synced_dir(TOOLS_DIR, common.job_id, common.task_id, args)?;
let crashes = if input_queue.is_none() {
get_synced_dir(CRASHES_DIR, common.job_id, common.task_id, args)
.ok()
.monitor_count(&event_sender)?
} else {
None
};
let reports = get_synced_dir(REPORTS_DIR, common.job_id, common.task_id, args)
.ok()
.monitor_count(&event_sender)?;
let no_repro = get_synced_dir(NO_REPRO_DIR, common.job_id, common.task_id, args)
.ok()
.monitor_count(&event_sender)?;
let unique_reports = get_synced_dir(UNIQUE_REPORTS_DIR, common.job_id, common.task_id, args)
.ok()
.monitor_count(&event_sender)?;

let config = Config {
analyzer_exe,
analyzer_options,
analyzer_env,
target_exe,
target_options,
input_queue,
crashes,
analysis,
tools: Some(tools),
reports,
unique_reports,
no_repro,
common,
};

Ok(config)
}

pub async fn run(args: &clap::ArgMatches, event_sender: Option<Sender<UiEvent>>) -> Result<()> {
let context = build_local_context(args, true, event_sender.clone()).await?;
let config = build_analysis_config(args, None, context.common_config.clone(), event_sender)?;
run_analysis(config).await
}

pub fn build_shared_args(required_task: bool) -> Vec<Arg> {
vec![
Arg::new(TARGET_EXE).long(TARGET_EXE).required(true),
Arg::new(TARGET_ENV)
.long(TARGET_ENV)
.requires(TARGET_EXE)
.num_args(0..),
Arg::new(TARGET_OPTIONS)
.long(TARGET_OPTIONS)
.default_value("{input}")
.value_delimiter(' ')
.help("Use a quoted string with space separation to denote multiple arguments"),
Arg::new(CRASHES_DIR)
.long(CRASHES_DIR)
.value_parser(value_parser!(PathBuf)),
Arg::new(ANALYZER_OPTIONS)
.long(ANALYZER_OPTIONS)
.requires(ANALYZER_EXE)
.value_delimiter(' ')
.help("Use a quoted string with space separation to denote multiple arguments"),
Arg::new(ANALYZER_ENV)
.long(ANALYZER_ENV)
.requires(ANALYZER_EXE)
.num_args(0..),
Arg::new(TOOLS_DIR)
.long(TOOLS_DIR)
.value_parser(value_parser!(PathBuf)),
Arg::new(ANALYZER_EXE)
.long(ANALYZER_EXE)
.requires(ANALYSIS_DIR)
.requires(CRASHES_DIR)
.required(required_task),
Arg::new(ANALYSIS_DIR)
.long(ANALYSIS_DIR)
.requires(ANALYZER_EXE)
.requires(CRASHES_DIR)
.required(required_task),
]
}

pub fn args(name: &'static str) -> Command {
Command::new(name)
.about("execute a local-only generic analysis")
.args(&build_shared_args(true))
}

#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
pub struct Analysis {
analyzer_exe: String,
Expand Down
Loading

0 comments on commit a551709

Please sign in to comment.