address clippy issues in agent (#490)

This commit is contained in:
bmc-msft
2021-02-02 14:41:27 -05:00
committed by GitHub
parent e60d697040
commit 02721f3ed9
11 changed files with 87 additions and 71 deletions

View File

@ -602,7 +602,7 @@ impl DebugHelpGuard {
) -> Result<SymLineInfo> { ) -> Result<SymLineInfo> {
let mut line_info: IMAGEHLP_LINEW64 = unsafe { MaybeUninit::zeroed().assume_init() }; let mut line_info: IMAGEHLP_LINEW64 = unsafe { MaybeUninit::zeroed().assume_init() };
line_info.SizeOfStruct = size_of::<IMAGEHLP_LINEW64>() as DWORD; line_info.SizeOfStruct = size_of::<IMAGEHLP_LINEW64>() as DWORD;
let mut displacement = 0 as DWORD; let mut displacement: DWORD = 0;
check_winapi(|| unsafe { check_winapi(|| unsafe {
SymGetLineFromInlineContextW( SymGetLineFromInlineContextW(
process_handle, process_handle,

View File

@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License. // Licensed under the MIT License.
#![allow(clippy::single_match)]
use std::{ use std::{
collections::hash_map, collections::hash_map,
fs, fs,
@ -405,14 +407,16 @@ impl Target {
bp.set_original_byte(Some(original_byte)); bp.set_original_byte(Some(original_byte));
bp.set_id(id); bp.set_id(id);
}) })
.or_insert(Breakpoint::new( .or_insert_with(|| {
address, Breakpoint::new(
kind, address,
/*enabled*/ true, kind,
/*original_byte*/ Some(original_byte), /*enabled*/ true,
/*hit_count*/ 0, /*original_byte*/ Some(original_byte),
id, /*hit_count*/ 0,
)); id,
)
});
write_instruction_byte(self.process_handle, address, 0xcc)?; write_instruction_byte(self.process_handle, address, 0xcc)?;

View File

@ -343,17 +343,11 @@ impl ExitStatus {
} }
pub fn is_normal_exit(&self) -> bool { pub fn is_normal_exit(&self) -> bool {
match self { matches!(self, ExitStatus::Code(_))
ExitStatus::Code(_) => true,
_ => false,
}
} }
pub fn is_timeout(&self) -> bool { pub fn is_timeout(&self) -> bool {
match self { matches!(self, ExitStatus::Timeout(_))
ExitStatus::Timeout(_) => true,
_ => false,
}
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License. // Licensed under the MIT License.
#![allow(clippy::match_like_matches_macro)]
#![allow(clippy::unknown_clippy_lints)] #![allow(clippy::unknown_clippy_lints)]
#![allow(clippy::single_component_path_imports)] #![allow(clippy::single_component_path_imports)]
#![allow(clippy::option_map_or_none)] #![allow(clippy::option_map_or_none)]

View File

@ -26,9 +26,9 @@ pub const CHECK_FUZZER_HELP: &str = "check_fuzzer_help";
pub const TARGET_EXE: &str = "target_exe"; pub const TARGET_EXE: &str = "target_exe";
pub const TARGET_ENV: &str = "target_env"; pub const TARGET_ENV: &str = "target_env";
pub const TARGET_OPTIONS: &str = "target_options"; pub const TARGET_OPTIONS: &str = "target_options";
pub const SUPERVISOR_EXE: &str = "supervisor_exe"; // pub const SUPERVISOR_EXE: &str = "supervisor_exe";
pub const SUPERVISOR_ENV: &str = "supervisor_env"; // pub const SUPERVISOR_ENV: &str = "supervisor_env";
pub const SUPERVISOR_OPTIONS: &str = "supervisor_options"; // pub const SUPERVISOR_OPTIONS: &str = "supervisor_options";
pub const GENERATOR_EXE: &str = "generator_exe"; pub const GENERATOR_EXE: &str = "generator_exe";
pub const GENERATOR_ENV: &str = "generator_env"; pub const GENERATOR_ENV: &str = "generator_env";
pub const GENERATOR_OPTIONS: &str = "generator_options"; pub const GENERATOR_OPTIONS: &str = "generator_options";
@ -36,7 +36,7 @@ pub const GENERATOR_OPTIONS: &str = "generator_options";
pub enum CmdType { pub enum CmdType {
Target, Target,
Generator, Generator,
Supervisor, // Supervisor,
} }
pub fn add_cmd_options( pub fn add_cmd_options(
@ -48,7 +48,7 @@ pub fn add_cmd_options(
) -> App<'static, 'static> { ) -> App<'static, 'static> {
let (exe_name, env_name, arg_name) = match cmd_type { let (exe_name, env_name, arg_name) = match cmd_type {
CmdType::Target => (TARGET_EXE, TARGET_ENV, TARGET_OPTIONS), CmdType::Target => (TARGET_EXE, TARGET_ENV, TARGET_OPTIONS),
CmdType::Supervisor => (SUPERVISOR_EXE, SUPERVISOR_ENV, SUPERVISOR_OPTIONS), // CmdType::Supervisor => (SUPERVISOR_EXE, SUPERVISOR_ENV, SUPERVISOR_OPTIONS),
CmdType::Generator => (GENERATOR_EXE, GENERATOR_ENV, GENERATOR_OPTIONS), CmdType::Generator => (GENERATOR_EXE, GENERATOR_ENV, GENERATOR_OPTIONS),
}; };
@ -78,7 +78,7 @@ pub fn add_cmd_options(
pub fn get_cmd_exe(cmd_type: CmdType, args: &clap::ArgMatches<'_>) -> Result<String> { pub fn get_cmd_exe(cmd_type: CmdType, args: &clap::ArgMatches<'_>) -> Result<String> {
let name = match cmd_type { let name = match cmd_type {
CmdType::Target => TARGET_EXE, CmdType::Target => TARGET_EXE,
CmdType::Supervisor => SUPERVISOR_EXE, // CmdType::Supervisor => SUPERVISOR_EXE,
CmdType::Generator => GENERATOR_EXE, CmdType::Generator => GENERATOR_EXE,
}; };
@ -89,7 +89,7 @@ pub fn get_cmd_exe(cmd_type: CmdType, args: &clap::ArgMatches<'_>) -> Result<Str
pub fn get_cmd_arg(cmd_type: CmdType, args: &clap::ArgMatches<'_>) -> Vec<String> { pub fn get_cmd_arg(cmd_type: CmdType, args: &clap::ArgMatches<'_>) -> Vec<String> {
let name = match cmd_type { let name = match cmd_type {
CmdType::Target => TARGET_OPTIONS, CmdType::Target => TARGET_OPTIONS,
CmdType::Supervisor => SUPERVISOR_OPTIONS, // CmdType::Supervisor => SUPERVISOR_OPTIONS,
CmdType::Generator => GENERATOR_OPTIONS, CmdType::Generator => GENERATOR_OPTIONS,
}; };
@ -102,7 +102,7 @@ pub fn get_cmd_env(
) -> Result<HashMap<String, String>> { ) -> Result<HashMap<String, String>> {
let env_name = match cmd_type { let env_name = match cmd_type {
CmdType::Target => TARGET_ENV, CmdType::Target => TARGET_ENV,
CmdType::Supervisor => SUPERVISOR_ENV, // CmdType::Supervisor => SUPERVISOR_ENV,
CmdType::Generator => GENERATOR_ENV, CmdType::Generator => GENERATOR_ENV,
}; };
@ -156,15 +156,13 @@ pub fn build_common_config(args: &ArgMatches<'_>) -> Result<CommonConfig> {
let setup_dir = if args.is_present(SETUP_DIR) { let setup_dir = if args.is_present(SETUP_DIR) {
value_t!(args, SETUP_DIR, PathBuf)? value_t!(args, SETUP_DIR, PathBuf)?
} else if args.is_present(TARGET_EXE) {
value_t!(args, TARGET_EXE, PathBuf)?
.parent()
.map(|x| x.to_path_buf())
.unwrap_or_default()
} else { } else {
if args.is_present(TARGET_EXE) { PathBuf::default()
value_t!(args, TARGET_EXE, PathBuf)?
.parent()
.map(|x| x.to_path_buf())
.unwrap_or_default()
} else {
PathBuf::default()
}
}; };
let config = CommonConfig { let config = CommonConfig {

View File

@ -91,18 +91,21 @@ impl GeneratorTask {
} }
async fn fuzzing_loop(&self, heartbeat_client: Option<TaskHeartbeatClient>) -> Result<()> { async fn fuzzing_loop(&self, heartbeat_client: Option<TaskHeartbeatClient>) -> Result<()> {
let tester = Tester::new( let mut tester = Tester::new(
&self.config.common.setup_dir, &self.config.common.setup_dir,
&self.config.target_exe, &self.config.target_exe,
&self.config.target_options, &self.config.target_options,
&self.config.target_env, &self.config.target_env,
&self.config.target_timeout,
self.config.check_asan_log,
false,
self.config.check_debugger,
self.config.check_retry_count,
); );
tester
.check_asan_log(self.config.check_asan_log)
.check_debugger(self.config.check_debugger)
.check_retry_count(self.config.check_retry_count);
if let Some(timeout) = self.config.target_timeout {
tester.timeout(timeout);
}
loop { loop {
for corpus_dir in &self.config.readonly_inputs { for corpus_dir in &self.config.readonly_inputs {
heartbeat_client.alive(); heartbeat_client.alive();

View File

@ -118,18 +118,18 @@ pub struct GenericReportProcessor<'a> {
impl<'a> GenericReportProcessor<'a> { impl<'a> GenericReportProcessor<'a> {
pub fn new(config: &'a Config, heartbeat_client: Option<TaskHeartbeatClient>) -> Self { pub fn new(config: &'a Config, heartbeat_client: Option<TaskHeartbeatClient>) -> Self {
let tester = Tester::new( let mut tester = Tester::new(
&config.common.setup_dir, &config.common.setup_dir,
&config.target_exe, &config.target_exe,
&config.target_options, &config.target_options,
&config.target_env, &config.target_env,
&config.target_timeout,
config.check_asan_log,
false,
config.check_debugger,
config.check_retry_count,
); );
tester
.check_asan_log(config.check_asan_log)
.check_debugger(config.check_debugger)
.check_retry_count(config.check_retry_count);
Self { Self {
config, config,
tester, tester,

View File

@ -12,7 +12,7 @@ use anyhow::{Error, Result};
use std::{collections::HashMap, path::Path, time::Duration}; use std::{collections::HashMap, path::Path, time::Duration};
use tempfile::tempdir; use tempfile::tempdir;
const DEFAULT_TIMEOUT_SECS: u64 = 5; const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5);
const CRASH_SITE_UNAVAILABLE: &str = "<crash site unavailable>"; const CRASH_SITE_UNAVAILABLE: &str = "<crash site unavailable>";
pub struct Tester<'a> { pub struct Tester<'a> {
@ -47,26 +47,45 @@ impl<'a> Tester<'a> {
exe_path: &'a Path, exe_path: &'a Path,
arguments: &'a [String], arguments: &'a [String],
environ: &'a HashMap<String, String>, environ: &'a HashMap<String, String>,
timeout: &'a Option<u64>,
check_asan_log: bool,
check_asan_stderr: bool,
check_debugger: bool,
check_retry_count: u64,
) -> Self { ) -> Self {
let timeout = Duration::from_secs(timeout.unwrap_or(DEFAULT_TIMEOUT_SECS));
Self { Self {
setup_dir, setup_dir,
exe_path, exe_path,
arguments, arguments,
environ, environ,
timeout, timeout: DEFAULT_TIMEOUT,
check_asan_log, check_asan_log: false,
check_asan_stderr, check_asan_stderr: false,
check_debugger, check_debugger: true,
check_retry_count, check_retry_count: 0,
} }
} }
pub fn timeout(&mut self, value: u64) -> &mut Self {
self.timeout = Duration::from_secs(value);
self
}
pub fn check_asan_log(&mut self, value: bool) -> &mut Self {
self.check_asan_log = value;
self
}
pub fn check_asan_stderr(&mut self, value: bool) -> &mut Self {
self.check_asan_stderr = value;
self
}
pub fn check_debugger(&mut self, value: bool) -> &mut Self {
self.check_debugger = value;
self
}
pub fn check_retry_count(&mut self, value: u64) -> &mut Self {
self.check_retry_count = value;
self
}
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
async fn test_input_debugger( async fn test_input_debugger(
&self, &self,

View File

@ -162,17 +162,11 @@ impl<'a> LibFuzzer<'a> {
let mut options = self.options.to_owned(); let mut options = self.options.to_owned();
options.push("{input}".to_string()); options.push("{input}".to_string());
let tester = Tester::new( let mut tester = Tester::new(&self.setup_dir, &self.exe, &options, &self.env);
&self.setup_dir, tester.check_asan_stderr(true).check_retry_count(retry);
&self.exe, if let Some(timeout) = timeout {
&options, tester.timeout(timeout);
&self.env, }
&timeout,
false,
true,
false,
retry,
);
tester.test_input(test_input.as_ref()).await tester.test_input(test_input.as_ref()).await
} }

View File

@ -2,8 +2,11 @@
// Licensed under the MIT License. // Licensed under the MIT License.
use crate::fs::{onefuzz_etc, write_file}; use crate::fs::{onefuzz_etc, write_file};
use anyhow::{Context, Result}; #[cfg(target_os = "linux")]
use anyhow::Context;
use anyhow::Result;
use reqwest_retry::SendRetry; use reqwest_retry::SendRetry;
#[cfg(target_os = "linux")]
use std::path::Path; use std::path::Path;
use std::time::Duration; use std::time::Duration;
use tokio::fs; use tokio::fs;

View File

@ -29,12 +29,12 @@ mkdir -p artifacts/agent
cd src/agent cd src/agent
cargo fmt -- --check cargo fmt -- --check
# RUSTSEC-2019-0031: a dependency spin (pulled in from ring) is not actively maintained
# RUSTSEC-2020-0016: a dependency net2 (pulled in from tokio) is deprecated # RUSTSEC-2020-0016: a dependency net2 (pulled in from tokio) is deprecated
# RUSTSEC-2020-0036: a dependency failure (pulled from proc-maps) is deprecated # RUSTSEC-2020-0036: a dependency failure (pulled from proc-maps) is deprecated
cargo audit --deny warnings --deny unmaintained --deny unsound --deny yanked --ignore RUSTSEC-2019-0031 --ignore RUSTSEC-2020-0016 --ignore RUSTSEC-2020-0036 cargo audit --deny warnings --deny unmaintained --deny unsound --deny yanked --ignore RUSTSEC-2020-0016 --ignore RUSTSEC-2020-0036
cargo-license -j > data/licenses.json cargo-license -j > data/licenses.json
cargo build --release --locked cargo build --release --locked
cargo clippy --release -- -D warnings
# export RUST_LOG=trace # export RUST_LOG=trace
export RUST_BACKTRACE=full export RUST_BACKTRACE=full
cargo test --release --manifest-path ./onefuzz-supervisor/Cargo.toml cargo test --release --manifest-path ./onefuzz-supervisor/Cargo.toml