Clippy for Cargo (#532)

* Clippy for Cargo

* clippy fixes

* clippy fixes

* edition

* fix

* wrong self hidden

* fix

* more clippy
This commit is contained in:
Dominik Maier 2022-02-11 14:34:01 +01:00 committed by GitHub
parent a4c9d2d19e
commit 7dad2153e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 138 additions and 29 deletions

View File

@ -4,6 +4,7 @@ version = "0.7.1"
authors = ["Andrea Fioraldi <andreafioraldi@gmail.com>", "Dominik Maier <domenukk@gmail.com>"]
edition = "2021"
build = "build.rs"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[features]
default = ["std"]

View File

@ -9,6 +9,7 @@ readme = "../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "testing", "security"]
edition = "2021"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[features]
default = ["std", "derive", "llmp_compression", "rand_trait", "fork"]
@ -63,7 +64,7 @@ intervaltree = { version = "0.2.7", default-features = false, features = ["serde
backtrace = {version = "0.3", optional = true} # Used to get the stacktrace in StacktraceObserver
serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] }
miniz_oxide = { version = "0.5", optional = true}
miniz_oxide = { version = "0.4.4", optional = true}
core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs", rev = "6648a7a", optional = true }
hostname = { version = "^0.3", optional = true } # Is there really no gethostname in the stdlib?
rand_core = { version = "0.5.1", optional = true } # This dependency allows us to export our RomuRand as rand::Rng. We cannot update to the latest version because it breaks compatibility to microsoft lain.

View File

@ -206,6 +206,14 @@ impl TryFrom<&Vec<u8>> for TcpRequest {
}
}
impl TryFrom<Vec<u8>> for TcpRequest {
type Error = Error;
fn try_from(bytes: Vec<u8>) -> Result<Self, Error> {
Ok(postcard::from_bytes(&bytes)?)
}
}
/// Messages for broker 2 broker connection.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TcpRemoteNewMessage {
@ -227,6 +235,14 @@ impl TryFrom<&Vec<u8>> for TcpRemoteNewMessage {
}
}
impl TryFrom<Vec<u8>> for TcpRemoteNewMessage {
type Error = Error;
fn try_from(bytes: Vec<u8>) -> Result<Self, Error> {
Ok(postcard::from_bytes(&bytes)?)
}
}
/// Responses for requests to the server.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum TcpResponse {
@ -263,6 +279,14 @@ impl TryFrom<&Vec<u8>> for TcpResponse {
}
}
impl TryFrom<Vec<u8>> for TcpResponse {
type Error = Error;
fn try_from(bytes: Vec<u8>) -> Result<Self, Error> {
Ok(postcard::from_bytes(&bytes)?)
}
}
/// Abstraction for listeners
#[cfg(feature = "std")]
#[derive(Debug)]
@ -1830,7 +1854,7 @@ where
let mut stream = TcpStream::connect(addr)?;
println!("B2B: Connected to {:?}", stream);
match (&recv_tcp_msg(&mut stream)?).try_into()? {
match recv_tcp_msg(&mut stream)?.try_into()? {
TcpResponse::BrokerConnectHello {
broker_shmem_description: _,
hostname,
@ -1849,7 +1873,7 @@ where
send_tcp_msg(&mut stream, &TcpRequest::RemoteBrokerHello { hostname })?;
let broker_id = match (&recv_tcp_msg(&mut stream)?).try_into()? {
let broker_id = match recv_tcp_msg(&mut stream)?.try_into()? {
TcpResponse::RemoteBrokerAccepted { broker_id } => {
println!("B2B: Got Connection Ack, broker_id {}", broker_id);
broker_id
@ -2106,7 +2130,7 @@ where
// We ignore errors completely as they may be timeout, or stream closings.
// Instead, we catch stream close when/if we next try to send.
if let Ok(val) = recv_tcp_msg(&mut stream) {
let msg: TcpRemoteNewMessage = (&val).try_into().expect(
let msg: TcpRemoteNewMessage = val.try_into().expect(
"Illegal message received from broker 2 broker connection - shutting down.",
);
@ -2267,7 +2291,7 @@ where
continue;
}
};
let req = match (&buf).try_into() {
let req = match buf.try_into() {
Ok(req) => req,
Err(e) => {
eprintln!("Could not deserialize tcp message: {:?}", e);
@ -2653,7 +2677,7 @@ where
let broker_shmem_description = if let TcpResponse::BrokerConnectHello {
broker_shmem_description,
hostname: _,
} = (&recv_tcp_msg(&mut stream)?).try_into()?
} = recv_tcp_msg(&mut stream)?.try_into()?
{
broker_shmem_description
} else {
@ -2674,7 +2698,7 @@ where
send_tcp_msg(&mut stream, &client_hello_req)?;
let client_id = if let TcpResponse::LocalClientAccepted { client_id } =
(&recv_tcp_msg(&mut stream)?).try_into()?
recv_tcp_msg(&mut stream)?.try_into()?
{
client_id
} else {

View File

@ -621,12 +621,12 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
if (status & FS_OPT_SHDMEM_FUZZ == FS_OPT_SHDMEM_FUZZ) && map.is_some() {
println!("Using SHARED MEMORY FUZZING feature.");
send_status = send_status | FS_OPT_SHDMEM_FUZZ;
send_status |= FS_OPT_SHDMEM_FUZZ;
}
if (status & FS_OPT_AUTODICT == FS_OPT_AUTODICT) && self.autotokens.is_some() {
println!("Using AUTODICT feature");
send_status = send_status | FS_OPT_AUTODICT;
send_status |= FS_OPT_AUTODICT;
}
let send_len = forkserver.write_ctl(send_status)?;
@ -644,7 +644,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
));
}
if dict_size < 2 || dict_size > 0xffffff {
if !(2..=0xffffff).contains(&dict_size) {
return Err(Error::Forkserver(
"Dictionary has an illegal size".to_string(),
));
@ -782,8 +782,7 @@ impl<'a> ForkserverExecutorBuilder<'a, StdShMemProvider> {
#[must_use]
/// Place the input at this position and set the default filename for the input.
pub fn arg_input_file_std(self) -> Self {
let moved = self.arg_input_file(OUTFILE_STD);
moved
self.arg_input_file(OUTFILE_STD)
}
#[must_use]
@ -800,17 +799,15 @@ impl<'a> ForkserverExecutorBuilder<'a, StdShMemProvider> {
if item.as_ref() == "@@" && use_stdin {
use_stdin = false;
res.push(OsString::from(".cur_input"));
} else {
if let Some(name) = &self.out_filename {
if name == item.as_ref() && use_stdin {
use_stdin = false;
res.push(name.clone());
} else {
res.push(item.as_ref().to_os_string());
}
} else if let Some(name) = &self.out_filename {
if name == item.as_ref() && use_stdin {
use_stdin = false;
res.push(name.clone());
} else {
res.push(item.as_ref().to_os_string());
}
} else {
res.push(item.as_ref().to_os_string());
}
}
@ -851,6 +848,12 @@ impl<'a> ForkserverExecutorBuilder<'a, StdShMemProvider> {
}
}
impl<'a> Default for ForkserverExecutorBuilder<'a, StdShMemProvider> {
fn default() -> Self {
Self::new()
}
}
impl<EM, I, OT, S, SP, Z> Executor<EM, I, S, Z> for ForkserverExecutor<I, OT, S, SP>
where
I: Input + HasTargetBytes,

View File

@ -1571,6 +1571,10 @@ pub mod child_signal_handlers {
}
/// invokes the `post_exec` hook on all observer in case the child process crashes
///
/// # Safety
/// The function should only be called from a child crash handler.
/// It will dereference the `data` pointer and assume it's valid.
#[cfg(unix)]
pub unsafe fn child_crash_handler<E, I, OT, S>(
_signal: Signal,

View File

@ -51,6 +51,7 @@ where
I: Input,
S: HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,

View File

@ -123,6 +123,7 @@ where
O1: Observer<I, S> + PartialEq<O2>,
O2: Observer<I, S>,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,
@ -176,7 +177,7 @@ mod tests {
fn new(name: &str, value: bool) -> Self {
Self {
name: name.to_string(),
value: value,
value,
}
}
}

View File

@ -373,6 +373,7 @@ where
I: Input,
S: HasFeedbackStates + HasClientPerfMonitor + Debug,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
state: &mut S,
@ -599,6 +600,7 @@ where
O: MapObserver<Entry = usize>,
S: HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,

View File

@ -52,6 +52,7 @@ where
S: HasClientPerfMonitor,
{
/// `is_interesting ` return if an input is worth the addition to the corpus
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
state: &mut S,
@ -68,6 +69,7 @@ where
/// It also keeps track of introspection stats.
#[cfg(feature = "introspection")]
#[allow(clippy::too_many_arguments)]
#[allow(clippy::wrong_self_convention)]
fn is_interesting_introspection<EM, OT>(
&mut self,
state: &mut S,
@ -205,6 +207,7 @@ where
I: Input,
S: HasClientPerfMonitor + Debug,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
state: &mut S,
@ -229,6 +232,7 @@ where
}
#[cfg(feature = "introspection")]
#[allow(clippy::wrong_self_convention)]
fn is_interesting_introspection<EM, OT>(
&mut self,
state: &mut S,
@ -592,6 +596,7 @@ where
I: Input,
S: HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
state: &mut S,
@ -707,6 +712,7 @@ where
I: Input,
S: HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,
@ -739,6 +745,7 @@ where
I: Input,
S: HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,
@ -789,6 +796,7 @@ where
I: Input,
S: HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,
@ -844,6 +852,7 @@ where
I: Input,
S: HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,

View File

@ -78,6 +78,7 @@ impl<'a, S> Feedback<NautilusInput, S> for NautilusFeedback<'a>
where
S: HasMetadata + HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,

View File

@ -113,6 +113,7 @@ where
S: HasClientPerfMonitor + HasFeedbackStates,
O: ObserverWithHashField + Named + Debug,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,

View File

@ -8,7 +8,10 @@ Welcome to `LibAFL`
#![cfg_attr(unstable_feature, feature(specialization))]
// For `type_id` and owned things
#![cfg_attr(unstable_feature, feature(intrinsics))]
#![warn(clippy::cargo)]
#![deny(clippy::cargo_common_metadata)]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(
clippy::unreadable_literal,

View File

@ -5,13 +5,13 @@ use crate::mutators::str_decode;
#[cfg(target_os = "linux")]
use alloc::string::ToString;
use alloc::vec::Vec;
#[cfg(target_os = "linux")]
use core::slice::from_raw_parts;
use core::slice::Iter;
use core::{
mem::size_of,
ops::{Add, AddAssign},
};
#[cfg(target_os = "linux")]
use core::{ptr::null, slice::from_raw_parts};
use hashbrown::HashSet;
use serde::{Deserialize, Serialize};
#[cfg(feature = "std")]
@ -102,11 +102,14 @@ impl Tokens {
/// Create a token section from a start and an end pointer
/// Reads from an autotokens section, returning the count of new entries read
#[must_use]
///
/// # Safety
/// The caller must ensure that the region between `token_start` and `token_stop`
/// is a valid region, containing autotokens in the exepcted format.
#[cfg(target_os = "linux")]
pub unsafe fn from_ptrs(token_start: *const u8, token_stop: *const u8) -> Result<Self, Error> {
let mut ret = Self::default();
if token_start == null() || token_stop == null() {
if token_start.is_null() || token_stop.is_null() {
return Err(Error::IllegalArgument("token_start or token_stop is null. If you are using autotokens() you likely did not build your target with the \"AutoTokens\"-pass".to_string()));
}
if token_stop <= token_start {

View File

@ -9,6 +9,7 @@ readme = "../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "testing", "compiler"]
edition = "2021"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,6 +1,7 @@
//! Compiler Wrapper from `LibAFL`
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(
clippy::unreadable_literal,

View File

@ -9,6 +9,7 @@ repository = "https://github.com/AFLplusplus/LibAFL/"
readme = "README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "testing", "security"]
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -10,6 +10,7 @@ readme = "README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "testing", "security"]
build = "build.rs"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -70,6 +70,7 @@ impl<THasher: Hasher, THashBuilder: BuildHasher> CallStackCoverage<THasher, THas
self.pending = true;
}
#[allow(clippy::wrong_self_convention)]
pub fn is_interesting(&self) -> bool {
self.is_interesting
}

View File

@ -3,6 +3,13 @@ name = "dump_constraints"
version = "0.1.0"
edition = "2021"
authors = ["Julius Hohnerlein <julihoh@users.noreply.github.com>"]
description = "Dump Constraints, a lib to see the constraints oof a run"
documentation = "https://docs.rs/libafl"
repository = "https://github.com/AFLplusplus/LibAFL/"
readme = "../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "libafl", "ldpreload"]
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -112,7 +112,7 @@ fn main() {
.enumerate()
.filter(|(_, &v)| v != 0)
{
writeln!(&mut f, "{}\t{}", index, count).expect("failed to write coverage file");
writeln!(f, "{}\t{}", index, count).expect("failed to write coverage file");
}
}
@ -125,7 +125,7 @@ fn main() {
if opt.plain_text {
while let Some(message) = reader.next_message() {
if let Ok((id, message)) = message {
writeln!(&mut output_file, "{}\t{:?}", id, message)
writeln!(output_file, "{}\t{:?}", id, message)
.expect("failed to write to output file");
} else {
break;

View File

@ -3,6 +3,13 @@ name = "runtime_test"
version = "0.1.0"
edition = "2021"
authors = ["Julius Hohnerlein <julihoh@users.noreply.github.com>"]
description = "Runtime test of LibAFL fuzzing with symbolicc execution"
documentation = "https://docs.rs/libafl"
repository = "https://github.com/AFLplusplus/LibAFL/"
readme = "../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "libafl", "symbolic", "symcc", "symqemu", "fuzzer"]
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[lib]
crate-type = ["cdylib"]

View File

@ -9,6 +9,7 @@ readme = "../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "testing"]
edition = "2021"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[lib]
proc-macro = true

View File

@ -1,6 +1,7 @@
//! Derives for `LibAFL`
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(
clippy::unreadable_literal,

View File

@ -9,7 +9,7 @@ readme = "../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "frida", "instrumentation"]
edition = "2021"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[features]
default = []

View File

@ -615,6 +615,7 @@ where
I: Input + HasTargetBytes,
S: HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,

View File

@ -4,6 +4,7 @@ It can report coverage and, on supported architecutres, even reports memory acce
*/
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(
clippy::unreadable_literal,

View File

@ -9,6 +9,7 @@ readme = "../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "qemu", "instrumentation"]
edition = "2021"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[features]
python = ["pyo3", "pyo3-build-config"]

View File

@ -10,6 +10,7 @@ license = "MIT OR Apache-2.0"
keywords = ["fuzzing"]
edition = "2021"
build = "build.rs"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[features]
python = ["pyo3", "libafl_qemu/python", "pyo3-build-config"]

View File

@ -1,6 +1,7 @@
//! Sugar API to simplify the life of the naive user of `LibAFL`
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(
clippy::unreadable_literal,

View File

@ -9,6 +9,8 @@ readme = "../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "testing"]
edition = "2021"
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[features]
default = ["std", "sanitizers_flags"]

View File

@ -43,7 +43,6 @@ pub use __afl_area_ptr as EDGES_MAP_PTR;
///
/// This fn is safe to call, as long as the compilation diid not break, previously
#[cfg(target_os = "linux")]
#[must_use]
pub fn autotokens() -> Result<Tokens, Error> {
unsafe {
if __token_start.is_null() || __token_stop.is_null() {

View File

@ -2,6 +2,7 @@
//!
//!
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(
clippy::unreadable_literal,

View File

@ -1,4 +1,5 @@
cargo clippy --all --all-features --tests -- `
-D clippy::all `
-D clippy::pedantic `
-W clippy::similar_names `
-A clippy::type_repetition_in_bounds `

View File

@ -9,6 +9,7 @@ if [ "$1" != "--no-clean" ]; then
cargo clean -p libafl
fi
RUST_BACKTRACE=full cargo +nightly clippy --all --all-features --tests -- -Z macro-backtrace \
-D clippy::all \
-D clippy::pedantic \
-W clippy::similar_names \
-A clippy::type_repetition_in_bounds \

View File

@ -1,7 +1,15 @@
[package]
authors = ["Andrea Fioraldi <andreafioraldi@gmail.com>", "Dominik Maier <domenukk@gmail.com>"]
name = "deexit"
version = "0.1.0"
edition = "2021"
description = "DeExit: Replace exits with aborts to catch them during in-process fuzzing"
documentation = "https://docs.rs/libafl"
repository = "https://github.com/AFLplusplus/LibAFL/"
readme = "../../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "libafl", "ldpreload"]
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -2,6 +2,15 @@
name = "construct_automata"
version = "0.1.0"
edition = "2021"
authors = ["Andrea Fioraldi <andreafioraldi@gmail.com>", "Dominik Maier <domenukk@gmail.com>"]
description = "LibAFL Gramatron Gramar Construction"
documentation = "https://docs.rs/libafl"
repository = "https://github.com/AFLplusplus/LibAFL/"
readme = "../../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "libafl", "gramatron", "grammar"]
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,7 +1,15 @@
[package]
authors = ["Andrea Fioraldi <andreafioraldi@gmail.com>", "Dominik Maier <domenukk@gmail.com>"]
name = "libafl_benches"
version = "0.7.1"
edition = "2021"
description = "LibAFL Benchmarks"
documentation = "https://docs.rs/libafl"
repository = "https://github.com/AFLplusplus/LibAFL/"
readme = "../../README.md"
license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "libafl", "benchmarks"]
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
[dev-dependencies]
criterion = "0.3" # Benchmarking