Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
epi052 committed Oct 14, 2023
1 parent fae3982 commit 24f355d
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 20 deletions.
13 changes: 13 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ pub enum FeroxFuzzError {
source: libafl::Error,
},

/// Represents a failure to convert between two number types
#[error("Conversion from {value}_{from} to {to} failed")]
ConversionError {
/// value that couldn't be converted
value: String,

/// type to which conversion was attempted
to: String,

/// type from which conversion was attempted
from: String,
},

/// Represents a failure encountered during sending a request / receiving a response
#[error("An error occurred while sending the request: {kind:?} {message}")]
RequestError {
Expand Down
3 changes: 2 additions & 1 deletion src/fuzzers/async_fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,11 @@ where

// if any of the tasks failed, log the error and move along, nothing can really be
// done about it from here
#[allow(clippy::tuple_array_conversions)] // false positive
[first, second, third, fourth, fifth, sixth]
.into_iter()
.filter_map(|result| match result {
Ok(_) => None,
Ok(()) => None,
Err(err) => Some(err),
})
.for_each(|err| {
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Debug for FuzzingLoopHook {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("FuzzingLoopHook")
.field("called", &self.called)
.finish()
.finish_non_exhaustive() // purposely ignore callback
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/mutators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub trait Mutator: DynClone + AsAny + Named + Send + Sync {
}

if let Some(headers) = request.headers.as_mut() {
for (key, value) in headers.iter_mut() {
for (key, value) in &mut *headers {
if key.is_fuzzable() {
self.mutate(key, state)?;
notify_listeners(
Expand All @@ -188,7 +188,7 @@ pub trait Mutator: DynClone + AsAny + Named + Send + Sync {
}

if let Some(params) = request.params.as_mut() {
for (key, value) in params.iter_mut() {
for (key, value) in &mut *params {
if key.is_fuzzable() {
self.mutate(key, state)?;
notify_listeners(
Expand Down
22 changes: 21 additions & 1 deletion src/mutators/wordlist_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,27 @@ impl Mutator for ReplaceKeyword {
// piece of data, the index gathered above will move by some amount.
// the `step` value here is one piece of info necessary to calculate
// how far the move is.
let step = entry.len() as i64 - self.keyword.len() as i64;
let entry_length = i64::try_from(entry.len()).map_err(|source| {
tracing::error!(%source, "could not convert from {} to an i64", entry.len());

FeroxFuzzError::ConversionError {
value: format!("{}", entry.len()),
to: String::from("i64"),
from: String::from("usize"),
}
})?;

let keyword_length = i64::try_from(self.keyword.len()).map_err(|source| {
tracing::error!(%source, "could not convert from {} to an i64", self.keyword.len());

FeroxFuzzError::ConversionError {
value: format!("{}", self.keyword.len()),
to: String::from("i64"),
from: String::from("usize"),
}
})?;

let step = entry_length - keyword_length;

indices.iter().enumerate().for_each(|(i, &idx)| {
// when the step is negative, we need to subtract the
Expand Down
6 changes: 2 additions & 4 deletions src/requests/encoders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ macro_rules! encode_optional_field {
}

// buffer of a size big enough to hold the encoded value
let mut buffer = Vec::new();
buffer.resize($field.len() * 4 / 3 + 4, 0);
let mut buffer = vec![0; $field.len() * 4 / 3 + 4];

// perform the write
let written = general_purpose::URL_SAFE.encode_slice(
Expand Down Expand Up @@ -63,8 +62,7 @@ macro_rules! encode_optional_field {
}

// buffer of a size big enough to hold the encoded value
let mut buffer = Vec::new();
buffer.resize($field.len() * 2, 0);
let mut buffer = vec![0; $field.len() * 2];

// perform the write
//
Expand Down
2 changes: 1 addition & 1 deletion src/schedulers/ordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl OrderedScheduler {

let mut indices = Vec::with_capacity(corpora.len());

for (name, corpus) in corpora.iter() {
for (name, corpus) in &*corpora {
let length = corpus.len();

if length == 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/schedulers/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl std::fmt::Debug for ProductScheduler {
f.debug_struct("ProductScheduler")
.field("current", &self.current)
.field("indices", &self.indices)
.finish()
.finish_non_exhaustive() // purposely skip state
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ impl Scheduler for ProductScheduler {

// The pattern is that when an index reaches its modulo value, it is
// reset to 0 and the next greater loop is incremented.
for index in self.indices[1..].iter_mut() {
for index in &mut self.indices[1..] {
// due to len==1 check above, the slice is ok
index.next()?;

Expand Down
2 changes: 1 addition & 1 deletion src/schedulers/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl RandomScheduler {
.read()
.map_or(0, |stats| stats.requests() as usize);

for (name, corpus) in corpora.iter() {
for (name, corpus) in &*corpora {
let length = corpus.len();

if length == 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/schedulers/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl std::fmt::Debug for UniqueProductScheduler {
f.debug_struct("UniqueProductScheduler")
.field("current", &self.current)
.field("indices", &self.indices)
.finish()
.finish_non_exhaustive() // purposely skip state
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl SharedState {
}

if let Some(headers) = request.headers() {
for (key, value) in headers.iter() {
for (key, value) in headers {
if key.is_fuzzable() {
guard.add(key.clone());

Expand All @@ -656,7 +656,7 @@ impl SharedState {
}

if let Some(params) = request.params() {
for (key, value) in params.iter() {
for (key, value) in params {
if key.is_fuzzable() {
guard.add(key.clone());

Expand Down Expand Up @@ -748,7 +748,7 @@ impl Display for SharedState {
writeln!(f, " Seed={}", self.seed)?;
writeln!(f, " Rng={:?}", self.rng)?;

for (key, corpus) in self.corpora.iter() {
for (key, corpus) in &*self.corpora {
if let Ok(guard) = corpus.read() {
writeln!(f, " Corpus[{key}]={guard},")?;
}
Expand All @@ -760,7 +760,7 @@ impl Display for SharedState {

if let Ok(guard) = self.metadata().read() {
#[allow(clippy::significant_drop_in_scrutinee)] // doesn't appear to be an accurate lint
for (key, value) in guard.iter() {
for (key, value) in &*guard {
writeln!(f, " Metadata[{key}]={value:?}")?;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ impl Statistics {
*self
.actions
.entry("request".to_string())
.or_insert_with(HashMap::new)
.or_default()
.entry(to_update)
.or_insert(0) += 1;
}
RequestOrResponse::Response => {
*self
.actions
.entry("response".to_string())
.or_insert_with(HashMap::new)
.or_default()
.entry(to_update)
.or_insert(0) += 1;
}
Expand Down

0 comments on commit 24f355d

Please sign in to comment.