From 6f4955619a3eda620edefe8009f21ae31f7580b0 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 2 Jul 2023 19:13:46 +0200 Subject: [PATCH] Latest fmt (#1339) --- libafl/examples/llmp_test/main.rs | 4 +++- libafl/src/bolts/llmp.rs | 15 +++++++++------ libafl/src/bolts/os/unix_shmem_server.rs | 8 +++++--- libafl/src/corpus/inmemory_ondisk.rs | 12 +++++++++--- libafl/src/executors/command.rs | 4 ++-- libafl/src/executors/forkserver.rs | 10 +++++----- libafl/src/mutators/token_mutations.rs | 8 ++++++-- libafl/src/schedulers/accounting.rs | 4 +++- libafl/src/schedulers/minimizer.rs | 4 +++- libafl/src/stages/mutational.rs | 4 +++- libafl/src/stages/tuneable.rs | 4 +++- libafl_frida/src/alloc.rs | 8 ++++---- libafl_nyx/src/helper.rs | 10 ++++++---- 13 files changed, 61 insertions(+), 34 deletions(-) diff --git a/libafl/examples/llmp_test/main.rs b/libafl/examples/llmp_test/main.rs index 451a39c92d..8df7a27119 100644 --- a/libafl/examples/llmp_test/main.rs +++ b/libafl/examples/llmp_test/main.rs @@ -45,7 +45,9 @@ fn adder_loop(port: u16) -> Result<(), Box> { loop { let mut msg_counter = 0; loop { - let Some((sender, tag, buf)) = client.recv_buf()? else { break }; + let Some((sender, tag, buf)) = client.recv_buf()? else { + break; + }; msg_counter += 1; match tag { _TAG_SIMPLE_U32_V1 => { diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index 22280b9bd0..920069c574 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -3045,11 +3045,12 @@ where let TcpResponse::BrokerConnectHello { broker_shmem_description, hostname: _, - } = recv_tcp_msg(&mut stream)?.try_into()? else { + } = recv_tcp_msg(&mut stream)?.try_into()? + else { return Err(Error::illegal_state( "Received unexpected Broker Hello".to_string(), )); - }; + }; let map = LlmpSharedMap::existing( shmem_provider.shmem_from_description(broker_shmem_description)?, @@ -3064,11 +3065,13 @@ where send_tcp_msg(&mut stream, &client_hello_req)?; - let TcpResponse::LocalClientAccepted { client_id } = recv_tcp_msg(&mut stream)?.try_into()? else { - return Err(Error::illegal_state( - "Unexpected Response from Broker".to_string(), + let TcpResponse::LocalClientAccepted { client_id } = + recv_tcp_msg(&mut stream)?.try_into()? + else { + return Err(Error::illegal_state( + "Unexpected Response from Broker".to_string(), )); - }; + }; // Set our ID to the one the broker sent us.. // This is mainly so we can filter out our own msgs later. diff --git a/libafl/src/bolts/os/unix_shmem_server.rs b/libafl/src/bolts/os/unix_shmem_server.rs index 9142e12bc0..d56ee0fa13 100644 --- a/libafl/src/bolts/os/unix_shmem_server.rs +++ b/libafl/src/bolts/os/unix_shmem_server.rs @@ -353,9 +353,11 @@ impl Drop for ShMemServiceThread { fn drop(&mut self) { if self.join_handle.is_some() { log::info!("Stopping ShMemService"); - let Ok(mut stream) = UnixStream::connect_to_unix_addr( - &UnixSocketAddr::new(UNIX_SERVER_NAME).unwrap(), - ) else { return }; + let Ok(mut stream) = + UnixStream::connect_to_unix_addr(&UnixSocketAddr::new(UNIX_SERVER_NAME).unwrap()) + else { + return; + }; let body = postcard::to_allocvec(&ServedShMemRequest::Exit).unwrap(); diff --git a/libafl/src/corpus/inmemory_ondisk.rs b/libafl/src/corpus/inmemory_ondisk.rs index b6353e3bb3..281f8673e8 100644 --- a/libafl/src/corpus/inmemory_ondisk.rs +++ b/libafl/src/corpus/inmemory_ondisk.rs @@ -144,7 +144,9 @@ where fn load_input_into(&self, testcase: &mut Testcase) -> Result<(), Error> { if testcase.input_mut().is_none() { let Some(file_path) = testcase.file_path().as_ref() else { - return Err(Error::illegal_argument("No file path set for testcase. Could not load inputs.")); + return Err(Error::illegal_argument( + "No file path set for testcase. Could not load inputs.", + )); }; let input = I::from_file(file_path)?; testcase.set_input(input); @@ -155,10 +157,14 @@ where fn store_input_from(&self, testcase: &Testcase) -> Result<(), Error> { // Store the input to disk let Some(file_path) = testcase.file_path() else { - return Err(Error::illegal_argument("No file path set for testcase. Could not store input to disk.")); + return Err(Error::illegal_argument( + "No file path set for testcase. Could not store input to disk.", + )); }; let Some(input) = testcase.input() else { - return Err(Error::illegal_argument("No input available for testcase. Could not store anything.")); + return Err(Error::illegal_argument( + "No input available for testcase. Could not store anything.", + )); }; input.to_file(file_path) } diff --git a/libafl/src/executors/command.rs b/libafl/src/executors/command.rs index 43e161ddbf..256ab875bf 100644 --- a/libafl/src/executors/command.rs +++ b/libafl/src/executors/command.rs @@ -566,9 +566,9 @@ impl CommandExecutorBuilder { S: UsesInput, { let Some(program) = &self.program else { - return Err(Error::illegal_argument( + return Err(Error::illegal_argument( "CommandExecutor::builder: no program set!", - )); + )); }; let mut command = Command::new(program); diff --git a/libafl/src/executors/forkserver.rs b/libafl/src/executors/forkserver.rs index 0d3f07dc38..770e8626c2 100644 --- a/libafl/src/executors/forkserver.rs +++ b/libafl/src/executors/forkserver.rs @@ -330,11 +330,11 @@ impl Forkserver { pub fn read_st_timed(&mut self, timeout: &TimeSpec) -> Result, Error> { let mut buf: [u8; 4] = [0_u8; 4]; let Some(st_read) = self.st_pipe.read_end() else { - return Err(Error::file(io::Error::new( - ErrorKind::BrokenPipe, - "Read pipe end was already closed", - ))); - }; + return Err(Error::file(io::Error::new( + ErrorKind::BrokenPipe, + "Read pipe end was already closed", + ))); + }; let mut readfds = FdSet::new(); readfds.insert(st_read); diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index 6c803786b5..bb6fc31220 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -169,13 +169,17 @@ impl Tokens { if line.is_empty() || start == Some('#') { continue; } - let Some(pos_quote) = line.find('\"') else { return Err(Error::illegal_argument(format!("Illegal line: {line}"))) }; + let Some(pos_quote) = line.find('\"') else { + return Err(Error::illegal_argument(format!("Illegal line: {line}"))); + }; if line.chars().nth(line.len() - 1) != Some('"') { return Err(Error::illegal_argument(format!("Illegal line: {line}"))); } // extract item - let Some(item) = line.get(pos_quote + 1..line.len() - 1) else { return Err(Error::illegal_argument(format!("Illegal line: {line}"))) }; + let Some(item) = line.get(pos_quote + 1..line.len() - 1) else { + return Err(Error::illegal_argument(format!("Illegal line: {line}"))); + }; if item.is_empty() { continue; } diff --git a/libafl/src/schedulers/accounting.rs b/libafl/src/schedulers/accounting.rs index 92d6549c9e..63e79eb8bb 100644 --- a/libafl/src/schedulers/accounting.rs +++ b/libafl/src/schedulers/accounting.rs @@ -281,7 +281,9 @@ where /// Cull the `Corpus` #[allow(clippy::unused_self)] pub fn accounting_cull(&self, state: &mut CS::State) -> Result<(), Error> { - let Some(top_rated) = state.metadata_map().get::() else { return Ok(()) }; + let Some(top_rated) = state.metadata_map().get::() else { + return Ok(()); + }; for (_key, idx) in &top_rated.map { let mut entry = state.corpus().get(*idx)?.borrow_mut(); diff --git a/libafl/src/schedulers/minimizer.rs b/libafl/src/schedulers/minimizer.rs index 187509344a..43ad19500e 100644 --- a/libafl/src/schedulers/minimizer.rs +++ b/libafl/src/schedulers/minimizer.rs @@ -322,7 +322,9 @@ where /// Cull the `Corpus` using the `MinimizerScheduler` #[allow(clippy::unused_self)] pub fn cull(&self, state: &mut CS::State) -> Result<(), Error> { - let Some(top_rated) = state.metadata_map().get::() else { return Ok(()) }; + let Some(top_rated) = state.metadata_map().get::() else { + return Ok(()); + }; let mut acc = HashSet::new(); diff --git a/libafl/src/stages/mutational.rs b/libafl/src/stages/mutational.rs index 15061fd1a0..ff574a34f6 100644 --- a/libafl/src/stages/mutational.rs +++ b/libafl/src/stages/mutational.rs @@ -119,7 +119,9 @@ where start_timer!(state); let mut testcase = state.corpus().get(corpus_idx)?.borrow_mut(); - let Ok(input) = I::try_transform_from(&mut testcase, state, corpus_idx) else { return Ok(()); }; + let Ok(input) = I::try_transform_from(&mut testcase, state, corpus_idx) else { + return Ok(()); + }; drop(testcase); mark_feature_time!(state, PerfFeature::GetInputFromCorpus); diff --git a/libafl/src/stages/tuneable.rs b/libafl/src/stages/tuneable.rs index 6ce22a1b86..f7b45499e4 100644 --- a/libafl/src/stages/tuneable.rs +++ b/libafl/src/stages/tuneable.rs @@ -120,7 +120,9 @@ where start_timer!(state); let mut testcase = state.corpus().get(corpus_idx)?.borrow_mut(); - let Ok(input) = I::try_transform_from(&mut testcase, state, corpus_idx) else { return Ok(()); }; + let Ok(input) = I::try_transform_from(&mut testcase, state, corpus_idx) else { + return Ok(()); + }; drop(testcase); mark_feature_time!(state, PerfFeature::GetInputFromCorpus); diff --git a/libafl_frida/src/alloc.rs b/libafl_frida/src/alloc.rs index a40cf0f730..fe7bb00fca 100644 --- a/libafl_frida/src/alloc.rs +++ b/libafl_frida/src/alloc.rs @@ -351,11 +351,11 @@ impl Allocator { //log::trace!("freeing address: {:?}", ptr); let Some(metadata) = self.allocations.get_mut(&(ptr as usize)) else { if !ptr.is_null() { - AsanErrors::get_mut() + AsanErrors::get_mut() .report_error(AsanError::UnallocatedFree((ptr as usize, Backtrace::new()))); - } - return; - }; + } + return; + }; if metadata.freed { AsanErrors::get_mut().report_error(AsanError::DoubleFree(( diff --git a/libafl_nyx/src/helper.rs b/libafl_nyx/src/helper.rs index 47bf31c295..2184080997 100644 --- a/libafl_nyx/src/helper.rs +++ b/libafl_nyx/src/helper.rs @@ -60,15 +60,17 @@ impl NyxHelper { parent_cpu_id: Option, initial_timeout: Duration, ) -> Result { - let Some(sharedir) = target_dir.to_str() else { return Err(Error::illegal_argument("can't convert sharedir to str")) }; + let Some(sharedir) = target_dir.to_str() else { + return Err(Error::illegal_argument("can't convert sharedir to str")); + }; let work_dir = target_dir.join("workdir"); let work_dir = work_dir.to_str().expect("unable to convert workdir to str"); let nyx_type = if parallel_mode { let Some(parent_cpu_id) = parent_cpu_id else { return Err(Error::illegal_argument( - "please set parent_cpu_id in nyx parallel mode", - )) - }; + "please set parent_cpu_id in nyx parallel mode", + )); + }; if cpu_id == parent_cpu_id { NyxProcessType::PARENT } else {