Address clippy issues (#409)

This commit is contained in:
bmc-msft
2021-01-05 10:41:46 -05:00
committed by GitHub
parent 37f06bb324
commit 7e56efa6a8
22 changed files with 52 additions and 54 deletions

1
src/agent/Cargo.lock generated
View File

@ -2104,6 +2104,7 @@ dependencies = [
"backoff",
"log",
"reqwest",
"tokio",
]
[[package]]

View File

@ -261,8 +261,8 @@ pub struct ModuleImage {
impl ModuleImage {
pub fn new(map: MemoryMap) -> Result<Self> {
if let MMapPath::Path(..) = &map.pathname {
if map.perms.contains("x") {
return Ok(ModuleImage { map });
if map.perms.contains('x') {
Ok(ModuleImage { map })
} else {
anyhow::bail!("memory mapping is not executable");
}

View File

@ -53,8 +53,8 @@ fn main() -> Result<(), Box<dyn Error>> {
let sha = run_cmd(&["git", "rev-parse", "HEAD"])?;
let hardcode_version = env::var("ONEFUZZ_SET_VERSION");
if hardcode_version.is_ok() {
print_values(hardcode_version.unwrap().as_ref(), &sha);
if let Ok(hardcode_version) = &hardcode_version {
print_values(hardcode_version, &sha);
return Ok(());
}

View File

@ -57,7 +57,7 @@ pub fn run(args: &clap::ArgMatches) -> Result<()> {
let mut rt = Runtime::new()?;
rt.block_on(merge_inputs(
config.clone(),
vec![config.clone().inputs[0].path.clone()],
vec![config.inputs[0].path.clone()],
))?;
Ok(())

View File

@ -129,7 +129,7 @@ async fn generate_input(
async fn start_fuzzing<'a>(
config: &GeneratorConfig,
corpus_dirs: Vec<impl AsRef<Path>>,
tester: Tester<'a>,
tester: Tester<'_>,
heartbeat_client: Option<TaskHeartbeatClient>,
) -> Result<()> {
let generator_tmp = "generator_tmp";

View File

@ -270,7 +270,7 @@ mod tests {
runtime_dir,
PathBuf::from(afl_fuzz_exe),
PathBuf::from(afl_test_binary),
fault_dir.clone(),
fault_dir,
corpus_dir,
&target_options,
&supervisor_options,

View File

@ -122,8 +122,10 @@ async fn test_ready_poll() {
let msg: Msg = 0;
let mut queue = TestQueue::default();
queue.pending = vec![msg];
let mut queue = TestQueue {
pending: vec![msg],
..Default::default()
};
task.trigger(Event::Poll(&mut queue)).await.unwrap();
@ -140,8 +142,9 @@ async fn test_polled_some_parse() {
task.set_state(State::Polled(Some(msg)));
let mut parser = TestParser::default();
parser.urls = vec![url.clone()]; // at index `msg`
let mut parser = TestParser {
urls: vec![url.clone()], // at index `msg`
};
task.trigger(Event::Parse(&mut parser)).await.unwrap();
@ -155,7 +158,6 @@ async fn test_polled_none_parse() {
task.set_state(State::Polled(None));
let mut parser = TestParser::default();
parser.urls = vec![];
task.trigger(Event::Parse(&mut parser)).await.unwrap();

View File

@ -124,7 +124,7 @@ async fn try_delete_blob(input_url: Url) -> Result<()> {
.await
{
Ok(_) => Ok(()),
Err(err) => Err(err.into()),
Err(err) => Err(err),
}
}

View File

@ -176,6 +176,6 @@ async fn try_delete_blob(input_url: Url) -> Result<()> {
.await
{
Ok(_) => Ok(()),
Err(err) => Err(err.into()),
Err(err) => Err(err),
}
}

View File

@ -153,7 +153,7 @@ impl CrashReport {
call_stack: asan_log.call_stack().to_vec(),
call_stack_sha256: asan_log.call_stack_sha256(),
asan_log: Some(asan_log.text().to_string()),
scariness_score: asan_log.scariness_score().into(),
scariness_score: asan_log.scariness_score(),
scariness_description: asan_log.scariness_description().to_owned(),
task_id,
job_id,

View File

@ -53,8 +53,8 @@ fn main() -> Result<(), Box<dyn Error>> {
let sha = run_cmd(&["git", "rev-parse", "HEAD"])?;
let hardcode_version = env::var("ONEFUZZ_SET_VERSION");
if hardcode_version.is_ok() {
print_values(hardcode_version.unwrap().as_ref(), &sha);
if let Ok(hardcode_version) = &hardcode_version {
print_values(hardcode_version, &sha);
return Ok(());
}

View File

@ -88,7 +88,7 @@ impl StaticConfig {
pub fn from_env() -> Result<Self> {
let instance_id = Uuid::parse_str(&std::env::var("ONEFUZZ_INSTANCE_ID")?)?;
let client_id = Uuid::parse_str(&std::env::var("ONEFUZZ_CLIENT_ID")?)?;
let client_secret = std::env::var("ONEFUZZ_CLIENT_SECRET")?.into();
let client_secret = std::env::var("ONEFUZZ_CLIENT_SECRET")?;
let tenant = std::env::var("ONEFUZZ_TENANT")?;
let onefuzz_url = Url::parse(&std::env::var("ONEFUZZ_URL")?)?;
let pool_name = std::env::var("ONEFUZZ_POOL")?;
@ -111,13 +111,9 @@ impl StaticConfig {
None
};
let credentials = ClientCredentials::new(
client_id,
client_secret,
onefuzz_url.clone().to_string(),
tenant,
)
.into();
let credentials =
ClientCredentials::new(client_id, client_secret, onefuzz_url.to_string(), tenant)
.into();
Ok(Self {
instance_id,
@ -240,7 +236,7 @@ impl Registration {
);
delay_with_jitter(REGISTRATION_RETRY_PERIOD).await;
}
Err(err) => return Err(err.into()),
Err(err) => return Err(err),
}
}

View File

@ -254,7 +254,7 @@ impl Coordinator {
Ok(response)
}
fn build_request<'a>(&self, request_type: RequestType<'a>) -> Result<Request> {
fn build_request(&self, request_type: RequestType<'_>) -> Result<Request> {
match request_type {
RequestType::PollCommands => self.poll_commands_request(),
RequestType::ClaimCommand(message_id) => self.claim_command_request(message_id),

View File

@ -62,20 +62,19 @@ fn main() -> Result<()> {
Opt::Run(opt) => run(opt)?,
Opt::Debug(opt) => debug::debug(opt)?,
Opt::Licenses => licenses()?,
Opt::Version => version()?,
Opt::Version => version(),
};
Ok(())
}
fn version() -> Result<()> {
fn version() {
println!(
"{} onefuzz:{} git:{}",
crate_version!(),
env!("ONEFUZZ_VERSION"),
env!("GIT_VERSION")
);
Ok(())
}
fn licenses() -> Result<()> {

View File

@ -38,11 +38,7 @@ impl Worker {
}
pub fn is_done(&self) -> bool {
if let Worker::Done(..) = self {
true
} else {
false
}
matches!(self, Worker::Done(..))
}
pub async fn update(

View File

@ -22,11 +22,12 @@ impl Fixture {
}
fn child_running(&self) -> ChildDouble {
let mut child = ChildDouble::default();
child.id = 123; // Not default
child.stderr = "stderr".into();
child.stdout = "stdout".into();
child
ChildDouble {
id: 123,
stderr: "stderr".into(),
stdout: "stdout".into(),
..Default::default()
}
}
fn child_exited(&self, exit_status: ExitStatus) -> ChildDouble {

View File

@ -190,7 +190,8 @@ pub async fn check_asan_string(mut data: String) -> Result<Option<AsanLog>> {
pub async fn check_asan_path(asan_dir: &Path) -> Result<Option<AsanLog>> {
let mut entries = fs::read_dir(asan_dir).await?;
while let Some(file) = entries.next().await {
// there should be only up to one file in asan_dir
if let Some(file) = entries.next().await {
let file = file?;
let mut asan_text = fs::read_to_string(file.path()).await?;
let asan = AsanLog::parse(asan_text.clone());

View File

@ -163,7 +163,7 @@ mod tests {
let mut len = 0;
let mut entries = fs::read_dir(dir).await.unwrap();
while let Some(_) = entries.next().await {
while entries.next().await.is_some() {
len += 1;
}

View File

@ -104,10 +104,11 @@ impl<'a> LibFuzzer<'a> {
}
// check if a max_time is already set
if let None = self
if self
.options
.iter()
.find(|o| o.starts_with("-max_total_time"))
.is_none()
{
cmd.arg(format!("-max_total_time={}", DEFAULT_MAX_TOTAL_SECONDS));
}
@ -252,13 +253,13 @@ mod tests {
#[test]
fn test_libfuzzer_line_pulse() {
let line = r"#2097152 pulse cov: 11 ft: 11 corp: 6/21b lim: 4096 exec/s: 699050 rss: 562Mb".into();
let line = r"#2097152 pulse cov: 11 ft: 11 corp: 6/21b lim: 4096 exec/s: 699050 rss: 562Mb";
let parsed = LibFuzzerLine::parse(line)
.expect("parse error")
.expect("no captures");
assert_eq!(parsed.iters(), 2097152);
assert_eq!(parsed.execs_sec(), 699050.0);
assert_eq!(parsed.execs_sec(), 699050.0_f64);
}
}

View File

@ -188,8 +188,8 @@ mod global {
assert_eq!(last_state, UNSET, "unexpected telemetry client state");
unsafe {
CLIENTS.instance = instance.map(|s| RwLock::new(s));
CLIENTS.shared = shared.map(|s| RwLock::new(s));
CLIENTS.instance = instance.map(RwLock::new);
CLIENTS.shared = shared.map(RwLock::new);
}
STATE.store(SET, SeqCst);

View File

@ -167,7 +167,7 @@ impl Crash {
let proc = stacktrace.trace(tid.as_raw() as u32)?;
let crashing_access = segv_access_addr(siginfo)?.map(|a| a.into());
let crashing_access = segv_access_addr(siginfo).map(|a| a.into());
let maps = proc_maps::get_process_maps(tid.as_raw())?;
@ -331,10 +331,10 @@ fn find_mapping(addr: u64, maps: &[MapRange]) -> Option<&MapRange> {
// Only 4 signals populate the `si_addr` field of `siginfo_t`. See `sigaction(2)`.
// On Linux, the most reliable one is SIGSEGV, which saves the address of the invalid
// memory access.
fn segv_access_addr(siginfo: Siginfo) -> Result<Option<u64>> {
fn segv_access_addr(siginfo: Siginfo) -> Option<u64> {
let is_segv = siginfo.si_signo == (SIGSEGV as i32);
let addr = if is_segv {
if is_segv {
// Accessing a union, safe because we checked `si_signo`.
let ptr = unsafe { siginfo.si_addr() };
@ -343,9 +343,7 @@ fn segv_access_addr(siginfo: Siginfo) -> Result<Option<u64>> {
Some(addr)
} else {
None
};
Ok(addr)
}
}
const CRASH_SIGNALS: &[Signal] = &[SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGABRT];

View File

@ -10,4 +10,7 @@ anyhow = "1.0"
async-trait = "0.1.36"
reqwest = { version = "0.10", features = ["json", "stream"] }
backoff = { version = "0.2.1", features = ["async-std"] }
log = "0.4"
log = "0.4"
[dev-dependencies]
tokio = { version = "0.2" }