Skip to content

Commit

Permalink
Fix Clippy (#2913)
Browse files Browse the repository at this point in the history
* clp

* lol

* this is false positive

* a

* clippy all

* aa
  • Loading branch information
tokatoka authored Jan 30, 2025
1 parent fd6271f commit d8df9b4
Show file tree
Hide file tree
Showing 49 changed files with 91 additions and 84 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ members = [
"utils/gramatron/construct_automata",
"utils/libafl_benches",
"utils/libafl_jumper",
"bindings/pylibafl",
]

default-members = [
"libafl",
"libafl_bolts",
Expand All @@ -36,6 +36,7 @@ default-members = [
]

exclude = [
"bindings/pylibafl",
"fuzzers",
"libafl_libfuzzer_runtime",
"utils/noaslr",
Expand Down
4 changes: 2 additions & 2 deletions bindings/pylibafl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
categories = ["development-tools::testing", "emulators", "embedded", "os"]

[dependencies]
pyo3 = { workspace = true, features = ["extension-module"] }
pyo3 = { version = "0.23.2", features = ["extension-module"] }
pyo3-log = { version = "0.12.0" }
libafl_sugar = { path = "../../libafl_sugar", version = "0.15.0", features = [
"python",
Expand All @@ -24,7 +24,7 @@ libafl_qemu = { path = "../../libafl_qemu", version = "0.15.0", features = [
] }

[build-dependencies]
pyo3-build-config = { workspace = true }
pyo3-build-config = "0.23.2"

[lib]
name = "pylibafl"
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/forkserver/libafl-fuzz/src/env_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn parse_envs(opt: &mut Opt) -> Result<(), Error> {
if let Ok(res) = std::env::var("AFL_MAP_SIZE") {
let map_size = validate_map_size(res.parse()?)?;
opt.map_size = Some(map_size);
};
}
if let Ok(res) = std::env::var("AFL_IGNORE_TIMEOUT") {
opt.ignore_timeouts = parse_bool(&res)?;
}
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/forkserver/libafl-fuzz/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ define_run_client!(state, mgr, fuzzer_dir, core_id, opt, is_main_node, {
// Enable autodict if configured
if !opt.no_autodict {
executor_builder = executor_builder.autotokens(&mut tokens);
};
}

// Finalize and build our Executor
SupportedExecutors::Forkserver(
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/forkserver/libafl-fuzz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn main() {
Ok(()) => unreachable!(),
Err(Error::ShuttingDown) => println!("Fuzzing stopped by user. Good bye."),
Err(err) => panic!("Failed to run launcher: {err:?}"),
};
}
}

#[expect(clippy::struct_excessive_bools)]
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/common/nautilus/grammartec/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'data, 'tree: 'data, 'ctx: 'data, W: Write, T: TreeLike> Unparser<'data, 't
Some(UnparseStep::Script(num, expr)) => self.unwrap_script(num, &expr),
Some(UnparseStep::PushBuffer()) => self.push_buffer(),
None => return false,
};
}
true
}

Expand Down
2 changes: 1 addition & 1 deletion libafl/src/corpus/inmemory_ondisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ mod tests {
Ok(None) => (),
Ok(_) => panic!("File {path:?} did not exist even though it should have?"),
Err(e) => panic!("An unexpected error occurred: {e}"),
};
}
drop(f);
fs::remove_file(path).unwrap();
}
Expand Down
6 changes: 3 additions & 3 deletions libafl/src/events/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ where
client_description,
);
}
};
}
}
}
}
Expand Down Expand Up @@ -829,7 +829,7 @@ where
Err(Error::shutting_down())
}
}?,
};
}
}
}
}
Expand Down Expand Up @@ -902,7 +902,7 @@ where
if let Some(remote_broker_addr) = self.remote_broker_addr {
log::info!("B2b: Connecting to {:?}", &remote_broker_addr);
broker.inner_mut().connect_b2b(remote_broker_addr)?;
};
}

broker.set_exit_after(exit_cleanly_after);

Expand Down
2 changes: 1 addition & 1 deletion libafl/src/events/llmp/restarting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ where
if let Some(remote_broker_addr) = remote_broker_addr {
log::info!("B2b: Connecting to {:?}", &remote_broker_addr);
broker.inner_mut().connect_b2b(remote_broker_addr)?;
};
}

if let Some(exit_cleanly_after) = self.exit_cleanly_after {
broker.set_exit_after(exit_cleanly_after);
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,6 @@ mod tests {
assert_eq!("test", o.0.name());
}
_ => panic!("mistmatch"),
};
}
}
}
2 changes: 1 addition & 1 deletion libafl/src/events/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
match Self::handle_in_broker(&mut self.monitor, &event)? {
BrokerEventResult::Forward => self.events.push(event),
BrokerEventResult::Handled => (),
};
}
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions libafl/src/events/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,10 @@ where

let buf = &buf[4..];
#[cfg(feature = "tcp_compression")]
let buf = self.compressor.decompress(buf)?;
let buf = &self.compressor.decompress(buf)?;

// make decompressed vec and slice compatible
let event = postcard::from_bytes(&buf)?;
let event = postcard::from_bytes(buf)?;

self.handle_in_client(fuzzer, executor, state, other_client_id, event)?;
count += 1;
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/executors/hooks/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub mod windows_exception_handler {
}
} else {
log::error!("Crashed without exception (probably due to SIGABRT)");
};
}

if data.current_input_ptr.is_null() {
{
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/monitors/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ impl TuiUi {
Cell::from(Span::raw("not measured")),
Cell::from(Span::raw(format!("{:.2}%", client.unmeasured * 100.0))),
]));
};
}
}

let table = Table::default()
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/mutators/encoded_mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl<S: HasRand> Mutator<EncodedInput, S> for EncodedCopyMutator {
let size = input.codes().len();
if size <= 1 {
return Ok(MutationResult::Skipped);
};
}

// # Safety
// it's larger than 1
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/mutators/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ mod tests {
{
MutationResult::Mutated => new_testcases.push(mutant),
MutationResult::Skipped => (),
};
}
}
}
inputs.append(&mut new_testcases);
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/mutators/scheduled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ where
}
let meta = LogMutationMetadata::new(log);
testcase.add_metadata(meta);
};
}
// Always reset the log for each run
self.mutation_log.clear();
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/mutators/token_mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,7 @@ fn check_if_text(buf: &[u8], max_len: usize) -> TextType {
}
if percent_ascii >= 99 {
return TextType::Ascii(ascii);
};
}
TextType::None
}

Expand Down
2 changes: 1 addition & 1 deletion libafl/src/schedulers/minimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ where
let reserve = if meta.map.is_empty() {
map_iter.size_hint().0
} else {
(map_iter.size_hint().0 + 1) / 2
map_iter.size_hint().0.div_ceil(2)
};
meta.map.reserve(reserve);

Expand Down
6 changes: 3 additions & 3 deletions libafl/src/stages/calibrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ where

if iter < CAL_STAGE_MAX {
iter += 2;
};
};
}
}

total_time += current_time() - start;

Expand Down Expand Up @@ -234,7 +234,7 @@ where
usize::from(*history == O::Entry::default());
*history = O::Entry::max_value();
unstable_entries.push(idx);
};
}
}

if !unstable_entries.is_empty() && iter < CAL_STAGE_MAX {
Expand Down
4 changes: 2 additions & 2 deletions libafl/src/stages/push/mutational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ where
) {
self.push_stage_helper_mut().end_of_iter(shared_state, true);
return Some(Err(err));
};
}

if let Err(err) = shared_state
.event_mgr
.maybe_report_progress(&mut shared_state.state, STATS_TIMEOUT_DEFAULT)
{
self.push_stage_helper_mut().end_of_iter(shared_state, true);
return Some(Err(err));
};
}
} else {
self.push_stage_helper_mut().reset_exit_kind();
}
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/stages/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) fn extract_metadata(bytes: &[u8]) -> UnicodeIdentificationMetadata {
core::str::from_utf8(&bytes[i..][..e.valid_up_to()]).unwrap()
});
if !s.is_empty() {
let mut entries = bitvec![0; s.bytes().len()];
let mut entries = bitvec![0; s.len()];
for (c_idx, _) in s.char_indices() {
entries.set(c_idx, true);
visited.set(i + c_idx, true);
Expand Down
2 changes: 1 addition & 1 deletion libafl_bolts/examples/llmp_test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn adder_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> {
sender,
buf.len()
),
};
}
}

if current_result != last_result {
Expand Down
18 changes: 9 additions & 9 deletions libafl_bolts/src/llmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ where
pub fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> {
if let Some(msg) = unsafe { self.alloc_next_if_space(buf_len) } {
return Ok(msg);
};
}

/* no more space left! We'll have to start a new page */
unsafe {
Expand Down Expand Up @@ -1767,7 +1767,7 @@ where

// Store the last msg for next time
self.last_msg_recvd = msg;
};
}
Ok(ret)
}

Expand Down Expand Up @@ -2745,7 +2745,7 @@ where
"Error adding client! PANIC! {e:?}"
)));
}
};
}
}
// handle all other messages
_ => {
Expand Down Expand Up @@ -2957,7 +2957,7 @@ where
"Unexpected response from B2B server received.".to_string(),
))
}
};
}

let hostname = hostname::get()
.unwrap_or_else(|_| "<unknown>".into())
Expand Down Expand Up @@ -3282,7 +3282,7 @@ where
match Self::announce_new_client(sender, shmem_description) {
Ok(()) => (),
Err(e) => log::info!("Error forwarding client on map: {e:?}"),
};
}

if let Err(e) = send_tcp_msg(
&mut stream,
Expand All @@ -3291,7 +3291,7 @@ where
},
) {
log::info!("An error occurred sending via tcp {e}");
};
}
current_client_id.0 += 1;
}
TcpRequest::RemoteBrokerHello { hostname } => {
Expand All @@ -3315,11 +3315,11 @@ where
{
if Self::announce_new_client(sender, &shmem_description).is_err() {
log::info!("B2B: Error announcing client {shmem_description:?}");
};
}
current_client_id.0 += 1;
}
}
};
}
}

#[cfg(feature = "std")]
Expand Down Expand Up @@ -3417,7 +3417,7 @@ where
);
}
ListenerStream::Empty() => {}
};
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion libafl_bolts/src/minibsod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Er
match std::fs::read_to_string("/proc/self/maps") {
Ok(maps) => writer.write_all(maps.as_bytes())?,
Err(e) => writeln!(writer, "Couldn't load mappings: {e:?}")?,
};
}

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions libafl_bolts/src/os/unix_shmem_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ where
log::error!("Error polling for activity: {e:?}");
continue;
}
};
}
let copied_poll_fds: Vec<PollFd> = poll_fds.clone();
for poll_fd in copied_poll_fds {
let revents = poll_fd.revents().expect("revents should not be None");
Expand All @@ -681,7 +681,7 @@ where
Err(e) => {
log::info!("Ignoring failed read from client {e:?} {poll_fd:?}");
}
};
}
} else {
let (stream, _addr) = match listener.accept_unix_addr() {
Ok(stream_val) => stream_val,
Expand Down Expand Up @@ -716,7 +716,7 @@ where
Err(e) => {
log::info!("Ignoring failed read from client {e:?}");
}
};
}
}
} else {
//log::warn!("Unknown revents flags: {:?}", revents);
Expand Down
2 changes: 1 addition & 1 deletion libafl_bolts/src/os/unix_signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl Display for Signal {
Signal::SigTerm => write!(f, "SIGTERM")?,
Signal::SigInterrupt => write!(f, "SIGINT")?,
Signal::SigTrap => write!(f, "SIGTRAP")?,
};
}

Ok(())
}
Expand Down
Loading

0 comments on commit d8df9b4

Please sign in to comment.