Skip to content

Commit 7dad215

Browse files
authored
Clippy for Cargo (#532)
* Clippy for Cargo * clippy fixes * clippy fixes * edition * fix * wrong self hidden * fix * more clippy
1 parent a4c9d2d commit 7dad215

File tree

37 files changed

+138
-29
lines changed

37 files changed

+138
-29
lines changed

fuzzers/libfuzzer_stb_image_sugar/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.7.1"
44
authors = ["Andrea Fioraldi <[email protected]>", "Dominik Maier <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"
7+
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
78

89
[features]
910
default = ["std"]

libafl/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ readme = "../README.md"
99
license = "MIT OR Apache-2.0"
1010
keywords = ["fuzzing", "testing", "security"]
1111
edition = "2021"
12+
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
1213

1314
[features]
1415
default = ["std", "derive", "llmp_compression", "rand_trait", "fork"]
@@ -63,7 +64,7 @@ intervaltree = { version = "0.2.7", default-features = false, features = ["serde
6364
backtrace = {version = "0.3", optional = true} # Used to get the stacktrace in StacktraceObserver
6465

6566
serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] }
66-
miniz_oxide = { version = "0.5", optional = true}
67+
miniz_oxide = { version = "0.4.4", optional = true}
6768
core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs", rev = "6648a7a", optional = true }
6869
hostname = { version = "^0.3", optional = true } # Is there really no gethostname in the stdlib?
6970
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.

libafl/src/bolts/llmp.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ impl TryFrom<&Vec<u8>> for TcpRequest {
206206
}
207207
}
208208

209+
impl TryFrom<Vec<u8>> for TcpRequest {
210+
type Error = Error;
211+
212+
fn try_from(bytes: Vec<u8>) -> Result<Self, Error> {
213+
Ok(postcard::from_bytes(&bytes)?)
214+
}
215+
}
216+
209217
/// Messages for broker 2 broker connection.
210218
#[derive(Serialize, Deserialize, Debug, Clone)]
211219
pub struct TcpRemoteNewMessage {
@@ -227,6 +235,14 @@ impl TryFrom<&Vec<u8>> for TcpRemoteNewMessage {
227235
}
228236
}
229237

238+
impl TryFrom<Vec<u8>> for TcpRemoteNewMessage {
239+
type Error = Error;
240+
241+
fn try_from(bytes: Vec<u8>) -> Result<Self, Error> {
242+
Ok(postcard::from_bytes(&bytes)?)
243+
}
244+
}
245+
230246
/// Responses for requests to the server.
231247
#[derive(Serialize, Deserialize, Debug, Clone)]
232248
pub enum TcpResponse {
@@ -263,6 +279,14 @@ impl TryFrom<&Vec<u8>> for TcpResponse {
263279
}
264280
}
265281

282+
impl TryFrom<Vec<u8>> for TcpResponse {
283+
type Error = Error;
284+
285+
fn try_from(bytes: Vec<u8>) -> Result<Self, Error> {
286+
Ok(postcard::from_bytes(&bytes)?)
287+
}
288+
}
289+
266290
/// Abstraction for listeners
267291
#[cfg(feature = "std")]
268292
#[derive(Debug)]
@@ -1830,7 +1854,7 @@ where
18301854
let mut stream = TcpStream::connect(addr)?;
18311855
println!("B2B: Connected to {:?}", stream);
18321856

1833-
match (&recv_tcp_msg(&mut stream)?).try_into()? {
1857+
match recv_tcp_msg(&mut stream)?.try_into()? {
18341858
TcpResponse::BrokerConnectHello {
18351859
broker_shmem_description: _,
18361860
hostname,
@@ -1849,7 +1873,7 @@ where
18491873

18501874
send_tcp_msg(&mut stream, &TcpRequest::RemoteBrokerHello { hostname })?;
18511875

1852-
let broker_id = match (&recv_tcp_msg(&mut stream)?).try_into()? {
1876+
let broker_id = match recv_tcp_msg(&mut stream)?.try_into()? {
18531877
TcpResponse::RemoteBrokerAccepted { broker_id } => {
18541878
println!("B2B: Got Connection Ack, broker_id {}", broker_id);
18551879
broker_id
@@ -2106,7 +2130,7 @@ where
21062130
// We ignore errors completely as they may be timeout, or stream closings.
21072131
// Instead, we catch stream close when/if we next try to send.
21082132
if let Ok(val) = recv_tcp_msg(&mut stream) {
2109-
let msg: TcpRemoteNewMessage = (&val).try_into().expect(
2133+
let msg: TcpRemoteNewMessage = val.try_into().expect(
21102134
"Illegal message received from broker 2 broker connection - shutting down.",
21112135
);
21122136

@@ -2267,7 +2291,7 @@ where
22672291
continue;
22682292
}
22692293
};
2270-
let req = match (&buf).try_into() {
2294+
let req = match buf.try_into() {
22712295
Ok(req) => req,
22722296
Err(e) => {
22732297
eprintln!("Could not deserialize tcp message: {:?}", e);
@@ -2653,7 +2677,7 @@ where
26532677
let broker_shmem_description = if let TcpResponse::BrokerConnectHello {
26542678
broker_shmem_description,
26552679
hostname: _,
2656-
} = (&recv_tcp_msg(&mut stream)?).try_into()?
2680+
} = recv_tcp_msg(&mut stream)?.try_into()?
26572681
{
26582682
broker_shmem_description
26592683
} else {
@@ -2674,7 +2698,7 @@ where
26742698
send_tcp_msg(&mut stream, &client_hello_req)?;
26752699

26762700
let client_id = if let TcpResponse::LocalClientAccepted { client_id } =
2677-
(&recv_tcp_msg(&mut stream)?).try_into()?
2701+
recv_tcp_msg(&mut stream)?.try_into()?
26782702
{
26792703
client_id
26802704
} else {

libafl/src/executors/forkserver.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,12 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
621621

622622
if (status & FS_OPT_SHDMEM_FUZZ == FS_OPT_SHDMEM_FUZZ) && map.is_some() {
623623
println!("Using SHARED MEMORY FUZZING feature.");
624-
send_status = send_status | FS_OPT_SHDMEM_FUZZ;
624+
send_status |= FS_OPT_SHDMEM_FUZZ;
625625
}
626626

627627
if (status & FS_OPT_AUTODICT == FS_OPT_AUTODICT) && self.autotokens.is_some() {
628628
println!("Using AUTODICT feature");
629-
send_status = send_status | FS_OPT_AUTODICT;
629+
send_status |= FS_OPT_AUTODICT;
630630
}
631631

632632
let send_len = forkserver.write_ctl(send_status)?;
@@ -644,7 +644,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
644644
));
645645
}
646646

647-
if dict_size < 2 || dict_size > 0xffffff {
647+
if !(2..=0xffffff).contains(&dict_size) {
648648
return Err(Error::Forkserver(
649649
"Dictionary has an illegal size".to_string(),
650650
));
@@ -782,8 +782,7 @@ impl<'a> ForkserverExecutorBuilder<'a, StdShMemProvider> {
782782
#[must_use]
783783
/// Place the input at this position and set the default filename for the input.
784784
pub fn arg_input_file_std(self) -> Self {
785-
let moved = self.arg_input_file(OUTFILE_STD);
786-
moved
785+
self.arg_input_file(OUTFILE_STD)
787786
}
788787

789788
#[must_use]
@@ -800,17 +799,15 @@ impl<'a> ForkserverExecutorBuilder<'a, StdShMemProvider> {
800799
if item.as_ref() == "@@" && use_stdin {
801800
use_stdin = false;
802801
res.push(OsString::from(".cur_input"));
803-
} else {
804-
if let Some(name) = &self.out_filename {
805-
if name == item.as_ref() && use_stdin {
806-
use_stdin = false;
807-
res.push(name.clone());
808-
} else {
809-
res.push(item.as_ref().to_os_string());
810-
}
802+
} else if let Some(name) = &self.out_filename {
803+
if name == item.as_ref() && use_stdin {
804+
use_stdin = false;
805+
res.push(name.clone());
811806
} else {
812807
res.push(item.as_ref().to_os_string());
813808
}
809+
} else {
810+
res.push(item.as_ref().to_os_string());
814811
}
815812
}
816813

@@ -851,6 +848,12 @@ impl<'a> ForkserverExecutorBuilder<'a, StdShMemProvider> {
851848
}
852849
}
853850

851+
impl<'a> Default for ForkserverExecutorBuilder<'a, StdShMemProvider> {
852+
fn default() -> Self {
853+
Self::new()
854+
}
855+
}
856+
854857
impl<EM, I, OT, S, SP, Z> Executor<EM, I, S, Z> for ForkserverExecutor<I, OT, S, SP>
855858
where
856859
I: Input + HasTargetBytes,

libafl/src/executors/inprocess.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,10 @@ pub mod child_signal_handlers {
15711571
}
15721572

15731573
/// invokes the `post_exec` hook on all observer in case the child process crashes
1574+
///
1575+
/// # Safety
1576+
/// The function should only be called from a child crash handler.
1577+
/// It will dereference the `data` pointer and assume it's valid.
15741578
#[cfg(unix)]
15751579
pub unsafe fn child_crash_handler<E, I, OT, S>(
15761580
_signal: Signal,

libafl/src/feedbacks/concolic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ where
5151
I: Input,
5252
S: HasClientPerfMonitor,
5353
{
54+
#[allow(clippy::wrong_self_convention)]
5455
fn is_interesting<EM, OT>(
5556
&mut self,
5657
_state: &mut S,

libafl/src/feedbacks/differential.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ where
123123
O1: Observer<I, S> + PartialEq<O2>,
124124
O2: Observer<I, S>,
125125
{
126+
#[allow(clippy::wrong_self_convention)]
126127
fn is_interesting<EM, OT>(
127128
&mut self,
128129
_state: &mut S,
@@ -176,7 +177,7 @@ mod tests {
176177
fn new(name: &str, value: bool) -> Self {
177178
Self {
178179
name: name.to_string(),
179-
value: value,
180+
value,
180181
}
181182
}
182183
}

libafl/src/feedbacks/map.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ where
373373
I: Input,
374374
S: HasFeedbackStates + HasClientPerfMonitor + Debug,
375375
{
376+
#[allow(clippy::wrong_self_convention)]
376377
fn is_interesting<EM, OT>(
377378
&mut self,
378379
state: &mut S,
@@ -599,6 +600,7 @@ where
599600
O: MapObserver<Entry = usize>,
600601
S: HasClientPerfMonitor,
601602
{
603+
#[allow(clippy::wrong_self_convention)]
602604
fn is_interesting<EM, OT>(
603605
&mut self,
604606
_state: &mut S,

libafl/src/feedbacks/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ where
5252
S: HasClientPerfMonitor,
5353
{
5454
/// `is_interesting ` return if an input is worth the addition to the corpus
55+
#[allow(clippy::wrong_self_convention)]
5556
fn is_interesting<EM, OT>(
5657
&mut self,
5758
state: &mut S,
@@ -68,6 +69,7 @@ where
6869
/// It also keeps track of introspection stats.
6970
#[cfg(feature = "introspection")]
7071
#[allow(clippy::too_many_arguments)]
72+
#[allow(clippy::wrong_self_convention)]
7173
fn is_interesting_introspection<EM, OT>(
7274
&mut self,
7375
state: &mut S,
@@ -205,6 +207,7 @@ where
205207
I: Input,
206208
S: HasClientPerfMonitor + Debug,
207209
{
210+
#[allow(clippy::wrong_self_convention)]
208211
fn is_interesting<EM, OT>(
209212
&mut self,
210213
state: &mut S,
@@ -229,6 +232,7 @@ where
229232
}
230233

231234
#[cfg(feature = "introspection")]
235+
#[allow(clippy::wrong_self_convention)]
232236
fn is_interesting_introspection<EM, OT>(
233237
&mut self,
234238
state: &mut S,
@@ -592,6 +596,7 @@ where
592596
I: Input,
593597
S: HasClientPerfMonitor,
594598
{
599+
#[allow(clippy::wrong_self_convention)]
595600
fn is_interesting<EM, OT>(
596601
&mut self,
597602
state: &mut S,
@@ -707,6 +712,7 @@ where
707712
I: Input,
708713
S: HasClientPerfMonitor,
709714
{
715+
#[allow(clippy::wrong_self_convention)]
710716
fn is_interesting<EM, OT>(
711717
&mut self,
712718
_state: &mut S,
@@ -739,6 +745,7 @@ where
739745
I: Input,
740746
S: HasClientPerfMonitor,
741747
{
748+
#[allow(clippy::wrong_self_convention)]
742749
fn is_interesting<EM, OT>(
743750
&mut self,
744751
_state: &mut S,
@@ -789,6 +796,7 @@ where
789796
I: Input,
790797
S: HasClientPerfMonitor,
791798
{
799+
#[allow(clippy::wrong_self_convention)]
792800
fn is_interesting<EM, OT>(
793801
&mut self,
794802
_state: &mut S,
@@ -844,6 +852,7 @@ where
844852
I: Input,
845853
S: HasClientPerfMonitor,
846854
{
855+
#[allow(clippy::wrong_self_convention)]
847856
fn is_interesting<EM, OT>(
848857
&mut self,
849858
_state: &mut S,

libafl/src/feedbacks/nautilus.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl<'a, S> Feedback<NautilusInput, S> for NautilusFeedback<'a>
7878
where
7979
S: HasMetadata + HasClientPerfMonitor,
8080
{
81+
#[allow(clippy::wrong_self_convention)]
8182
fn is_interesting<EM, OT>(
8283
&mut self,
8384
_state: &mut S,

libafl/src/feedbacks/new_hash_feedback.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ where
113113
S: HasClientPerfMonitor + HasFeedbackStates,
114114
O: ObserverWithHashField + Named + Debug,
115115
{
116+
#[allow(clippy::wrong_self_convention)]
116117
fn is_interesting<EM, OT>(
117118
&mut self,
118119
_state: &mut S,

libafl/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Welcome to `LibAFL`
88
#![cfg_attr(unstable_feature, feature(specialization))]
99
// For `type_id` and owned things
1010
#![cfg_attr(unstable_feature, feature(intrinsics))]
11+
#![warn(clippy::cargo)]
12+
#![deny(clippy::cargo_common_metadata)]
1113
#![deny(rustdoc::broken_intra_doc_links)]
14+
#![deny(clippy::all)]
1215
#![deny(clippy::pedantic)]
1316
#![allow(
1417
clippy::unreadable_literal,

libafl/src/mutators/token_mutations.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use crate::mutators::str_decode;
55
#[cfg(target_os = "linux")]
66
use alloc::string::ToString;
77
use alloc::vec::Vec;
8+
#[cfg(target_os = "linux")]
9+
use core::slice::from_raw_parts;
810
use core::slice::Iter;
911
use core::{
1012
mem::size_of,
1113
ops::{Add, AddAssign},
1214
};
13-
#[cfg(target_os = "linux")]
14-
use core::{ptr::null, slice::from_raw_parts};
1515
use hashbrown::HashSet;
1616
use serde::{Deserialize, Serialize};
1717
#[cfg(feature = "std")]
@@ -102,11 +102,14 @@ impl Tokens {
102102

103103
/// Create a token section from a start and an end pointer
104104
/// Reads from an autotokens section, returning the count of new entries read
105-
#[must_use]
105+
///
106+
/// # Safety
107+
/// The caller must ensure that the region between `token_start` and `token_stop`
108+
/// is a valid region, containing autotokens in the exepcted format.
106109
#[cfg(target_os = "linux")]
107110
pub unsafe fn from_ptrs(token_start: *const u8, token_stop: *const u8) -> Result<Self, Error> {
108111
let mut ret = Self::default();
109-
if token_start == null() || token_stop == null() {
112+
if token_start.is_null() || token_stop.is_null() {
110113
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()));
111114
}
112115
if token_stop <= token_start {

libafl_cc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ readme = "../README.md"
99
license = "MIT OR Apache-2.0"
1010
keywords = ["fuzzing", "testing", "compiler"]
1111
edition = "2021"
12+
categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"]
1213

1314
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1415

libafl_cc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Compiler Wrapper from `LibAFL`
22
33
#![deny(rustdoc::broken_intra_doc_links)]
4+
#![deny(clippy::all)]
45
#![deny(clippy::pedantic)]
56
#![allow(
67
clippy::unreadable_literal,

0 commit comments

Comments
 (0)