Skip to content

Commit

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

* undo comment fmt

* add unstracked nyx files to gitignore

* fix

* windows, no_std

* fix

* fix

* more

* macos

* remove doctest

Co-authored-by: Dongjia "toka" Zhang <tokazerkje@outlook.com>
  • Loading branch information
domenukk and tokatoka committed Dec 5, 2022
1 parent ee58375 commit 68fbfc8
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 142 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ __pycache__
**/libxml2
**/corpus_discovered
**/libxml2-*.tar.gz

libafl_nyx/QEMU-Nyx
libafl_nyx/packer
5 changes: 1 addition & 4 deletions libafl/examples/llmp_test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ fn adder_loop(port: u16) -> ! {
}

if current_result != last_result {
println!(
"Adder handled {} messages, reporting {} to broker",
msg_counter, current_result
);
println!("Adder handled {msg_counter} messages, reporting {current_result} to broker");

client
.send_buf(_TAG_MATH_RESULT_V1, &current_result.to_le_bytes())
Expand Down
9 changes: 3 additions & 6 deletions libafl/src/bolts/core_affinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ impl Cores {

if cores.is_empty() {
return Err(Error::illegal_argument(format!(
"No cores specified! parsed: {}",
args
"No cores specified! parsed: {args}"
)));
}

Expand Down Expand Up @@ -591,8 +590,7 @@ mod apple {
Ok(())
} else {
Err(Error::unknown(format!(
"Failed to set_for_current {:?}",
result
"Failed to set_for_current {result:?}"
)))
}
}
Expand All @@ -615,8 +613,7 @@ mod apple {
Ok(())
} else {
Err(Error::unknown(format!(
"Failed to set_for_current {:?}",
result
"Failed to set_for_current {result:?}"
)))
}
}
Expand Down
39 changes: 13 additions & 26 deletions libafl/src/bolts/llmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,7 @@ unsafe fn _llmp_page_init<SHM: ShMem>(shmem: &mut SHM, sender_id: ClientId, allo
if !allow_reinit {
assert!(
(*page).magic != PAGE_INITIALIZED_MAGIC,
"Tried to initialize page {:?} twice (for shmem {:?})",
page,
shmem
"Tried to initialize page {page:?} twice (for shmem {shmem:?})"
);
}

Expand Down Expand Up @@ -641,10 +639,7 @@ where
}
Err(Error::File(e, _)) if e.kind() == ErrorKind::AddrInUse => {
// We are the client :)
println!(
"We're the client (internal port already bound by broker, {:#?})",
e
);
println!("We're the client (internal port already bound by broker, {e:#?})");
Ok(LlmpConnection::IsClient {
client: LlmpClient::create_attach_to_tcp(shmem_provider, port)?,
})
Expand Down Expand Up @@ -1082,8 +1077,7 @@ where
let page = self.out_shmems.last_mut().unwrap().page_mut();
if msg.is_null() || !llmp_msg_in_page(page, msg) {
return Err(Error::unknown(format!(
"Llmp Message {:?} is null or not in current page",
msg
"Llmp Message {msg:?} is null or not in current page"
)));
}

Expand Down Expand Up @@ -1189,8 +1183,7 @@ where
match unsafe { self.alloc_next_if_space(buf_len) } {
Some(msg) => Ok(msg),
None => Err(Error::unknown(format!(
"Error allocating {} bytes in shmap",
buf_len
"Error allocating {buf_len} bytes in shmap"
))),
}
}
Expand Down Expand Up @@ -1258,8 +1251,7 @@ where
|| tag == LLMP_TAG_UNSET
{
return Err(Error::unknown(format!(
"Reserved tag supplied to send_buf ({:#X})",
tag
"Reserved tag supplied to send_buf ({tag:#X})"
)));
}

Expand All @@ -1282,8 +1274,7 @@ where
|| tag == LLMP_TAG_UNSET
{
return Err(Error::unknown(format!(
"Reserved tag supplied to send_buf ({:#X})",
tag
"Reserved tag supplied to send_buf ({tag:#X})"
)));
}

Expand Down Expand Up @@ -1742,8 +1733,7 @@ where
let page_size = self.shmem.as_slice().len() - size_of::<LlmpPage>();
if offset > page_size {
Err(Error::illegal_argument(format!(
"Msg offset out of bounds (size: {}, requested offset: {})",
page_size, offset
"Msg offset out of bounds (size: {page_size}, requested offset: {offset})"
)))
} else {
unsafe { Ok(((*page).messages.as_mut_ptr() as *mut u8).add(offset) as *mut LlmpMsg) }
Expand Down Expand Up @@ -2048,7 +2038,7 @@ where
/// This function returns the [`ShMemDescription`] the client uses to place incoming messages.
/// The thread exits, when the remote broker disconnects.
#[cfg(feature = "std")]
#[allow(clippy::let_and_return)]
#[allow(clippy::let_and_return, clippy::too_many_lines)]
fn b2b_thread_on(
mut stream: TcpStream,
b2b_client_id: ClientId,
Expand Down Expand Up @@ -2106,8 +2096,7 @@ where
Ok(Some((client_id, tag, flags, payload))) => {
if client_id == b2b_client_id {
println!(
"Ignored message we probably sent earlier (same id), TAG: {:x}",
tag
"Ignored message we probably sent earlier (same id), TAG: {tag:x}"
);
continue;
}
Expand All @@ -2127,15 +2116,15 @@ where
payload: payload.to_vec(),
},
) {
println!("Got error {} while trying to forward a message to broker {}, exiting thread", e, peer_address);
println!("Got error {e} while trying to forward a message to broker {peer_address}, exiting thread");
return;
}
}
Err(Error::ShuttingDown) => {
println!("Local broker is shutting down, exiting thread");
return;
}
Err(e) => panic!("Error reading from local page! {}", e),
Err(e) => panic!("Error reading from local page! {e}"),
}
}

Expand Down Expand Up @@ -2171,8 +2160,7 @@ where
if let Error::File(e, _) = e {
if e.kind() == ErrorKind::UnexpectedEof {
println!(
"Broker {} seems to have disconnected, exiting",
peer_address
"Broker {peer_address} seems to have disconnected, exiting"
);
return;
}
Expand Down Expand Up @@ -2417,8 +2405,7 @@ where
println!("Error adding client! Ignoring: {e:?}");
#[cfg(not(feature = "std"))]
return Err(Error::unknown(format!(
"Error adding client! PANIC! {:?}",
e
"Error adding client! PANIC! {e:?}"
)));
}
};
Expand Down
3 changes: 1 addition & 2 deletions libafl/src/bolts/os/unix_signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ pub unsafe fn setup_signal_handler<T: 'static + Handler>(handler: &mut T) -> Res
// Rust always panics on OOM, so we will, too.
assert!(
!SIGNAL_STACK_PTR.is_null(),
"Failed to allocate signal stack with {} bytes!",
SIGNAL_STACK_SIZE
"Failed to allocate signal stack with {SIGNAL_STACK_SIZE} bytes!"
);
}
let mut ss: stack_t = mem::zeroed();
Expand Down
18 changes: 6 additions & 12 deletions libafl/src/bolts/shmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,7 @@ where
Ok(())
} else {
Err(Error::unknown(format!(
"Wrong result read from pipe! Expected 0, got {:?}",
ret
"Wrong result read from pipe! Expected 0, got {ret:?}"
)))
}
}
Expand Down Expand Up @@ -630,8 +629,7 @@ pub mod unix_shmem {
if shm_fd == -1 {
perror(b"shm_open\0".as_ptr() as *const _);
return Err(Error::unknown(format!(
"Failed to shm_open map with id {:?}",
shmem_ctr
"Failed to shm_open map with id {shmem_ctr:?}"
)));
}

Expand All @@ -640,8 +638,7 @@ pub mod unix_shmem {
perror(b"ftruncate\0".as_ptr() as *const _);
shm_unlink(filename_path.as_ptr() as *const _);
return Err(Error::unknown(format!(
"setup_shm(): ftruncate() failed for map with id {:?}",
shmem_ctr
"setup_shm(): ftruncate() failed for map with id {shmem_ctr:?}"
)));
}

Expand All @@ -659,8 +656,7 @@ pub mod unix_shmem {
close(shm_fd);
shm_unlink(filename_path.as_ptr() as *const _);
return Err(Error::unknown(format!(
"mmap() failed for map with id {:?}",
shmem_ctr
"mmap() failed for map with id {shmem_ctr:?}"
)));
}

Expand Down Expand Up @@ -691,8 +687,7 @@ pub mod unix_shmem {
perror(b"mmap\0".as_ptr() as *const _);
close(shm_fd);
return Err(Error::unknown(format!(
"mmap() failed for map with fd {:?}",
shm_fd
"mmap() failed for map with fd {shm_fd:?}"
)));
}

Expand Down Expand Up @@ -997,8 +992,7 @@ pub mod unix_shmem {
let fd = open(device_path.as_ptr(), O_RDWR);
if fd == -1 {
return Err(Error::unknown(format!(
"Failed to open the ashmem device at {:?}",
device_path
"Failed to open the ashmem device at {device_path:?}"
)));
}

Expand Down
10 changes: 6 additions & 4 deletions libafl/src/events/llmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,7 @@ where
executions: _,
} => {
#[cfg(feature = "std")]
println!(
"Received new Testcase from {} ({:?})",
_client_id, client_config
);
println!("Received new Testcase from {_client_id} ({client_config:?})");

let _res = if client_config.match_with(&self.configuration)
&& observers_buf.is_some()
Expand Down Expand Up @@ -890,8 +887,13 @@ where
mgr.to_env(_ENV_FUZZER_BROKER_CLIENT_INITIAL);

// First, create a channel from the current fuzzer to the next to store state between restarts.
#[cfg(unix)]
let mut staterestorer: StateRestorer<SP> =
StateRestorer::new(self.shmem_provider.new_shmem(256 * 1024 * 1024)?);

#[cfg(not(unix))]
let staterestorer: StateRestorer<SP> =
StateRestorer::new(self.shmem_provider.new_shmem(256 * 1024 * 1024)?);
// Store the information to a map.
staterestorer.write_to_env(_ENV_FUZZER_SENDER)?;

Expand Down
8 changes: 6 additions & 2 deletions libafl/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub static mut SHUTDOWN_SIGHANDLER_DATA: ShutdownSignalData = ShutdownSignalData
shutdown_handler: core::ptr::null(),
};

/// A signal handler for releasing staterestore shmem
/// This struct holds a pointer to StateRestore and clean up the shmem segment used by it.
/// A signal handler for releasing `StateRestore` `ShMem`
/// This struct holds a pointer to `StateRestore` and clean up the `ShMem` segment used by it.
#[cfg(all(unix, feature = "std"))]
#[derive(Debug, Clone)]
pub struct ShutdownSignalData {
Expand All @@ -58,6 +58,10 @@ pub type ShutdownFuncPtr =

/// Shutdown handler. `SigTerm`, `SigInterrupt`, `SigQuit` call this
/// We can't handle SIGKILL in the signal handler, this means that you shouldn't kill your fuzzer with `kill -9` because then the shmem segments are never freed
///
/// # Safety
///
/// This will acceess `data` and write to the global `data.staterestorer_ptr` if it's not null.
#[cfg(all(unix, feature = "std"))]
pub unsafe fn shutdown_handler<SP>(
signal: Signal,
Expand Down
8 changes: 6 additions & 2 deletions libafl/src/events/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ where
Ok(())
} else {
Err(Error::unknown(format!(
"Received illegal message that message should not have arrived: {:?}.",
event
"Received illegal message that message should not have arrived: {event:?}."
)))
}
}
Expand Down Expand Up @@ -445,8 +444,13 @@ where
// We start ourself as child process to actually fuzz
let mut staterestorer = if std::env::var(_ENV_FUZZER_SENDER).is_err() {
// First, create a place to store state in, for restarts.
#[cfg(unix)]
let mut staterestorer: StateRestorer<SP> =
StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?);
#[cfg(not(unix))]
let staterestorer: StateRestorer<SP> =
StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?);

//let staterestorer = { LlmpSender::new(shmem_provider.clone(), 0, false)? };
staterestorer.write_to_env(_ENV_FUZZER_SENDER)?;

Expand Down
3 changes: 1 addition & 2 deletions libafl/src/executors/forkserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ impl Forkserver {
Ok(_) => (),
Err(err) => {
return Err(Error::illegal_state(format!(
"Could not spawn the forkserver: {:#?}",
err
"Could not spawn the forkserver: {err:#?}"
)))
}
};
Expand Down
3 changes: 1 addition & 2 deletions libafl/src/executors/inprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,7 @@ mod unix_signal_handler {
let si_addr = { _info.si_addr() as usize };

eprintln!(
"We crashed at addr 0x{:x}, but are not in the target... Bug in the fuzzer? Exiting.",
si_addr
"We crashed at addr 0x{si_addr:x}, but are not in the target... Bug in the fuzzer? Exiting."
);

#[cfg(all(feature = "std", unix))]
Expand Down
3 changes: 1 addition & 2 deletions libafl/src/feedbacks/differential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ where
let o2_name = o2.name().to_string();
if o1_name == o2_name {
Err(Error::illegal_argument(format!(
"DiffFeedback: observer names must be different (both were {})",
o1_name
"DiffFeedback: observer names must be different (both were {o1_name})"
)))
} else {
Ok(Self {
Expand Down
3 changes: 1 addition & 2 deletions libafl/src/monitors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,7 @@ impl core::fmt::Display for ClientPerfMonitor {
// Create the formatted string
writeln!(
f,
" {:6.4}: Scheduler\n {:6.4}: Manager",
scheduler_percent, manager_percent
" {scheduler_percent:6.4}: Scheduler\n {manager_percent:6.4}: Manager"
)?;

// Calculate each stage
Expand Down
6 changes: 2 additions & 4 deletions libafl/src/mutators/token_mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ impl Tokens {
}
if token_stop < token_start {
return Err(Error::illegal_argument(format!(
"Tried to create tokens from illegal section: stop < start ({:?} < {:?})",
token_stop, token_start
"Tried to create tokens from illegal section: stop < start ({token_stop:?} < {token_start:?})"
)));
}
let section_size: usize = token_stop.offset_from(token_start).try_into().unwrap();
Expand Down Expand Up @@ -185,8 +184,7 @@ impl Tokens {
Ok(val) => val,
Err(_) => {
return Err(Error::illegal_argument(format!(
"Illegal line (hex decoding): {}",
line
"Illegal line (hex decoding): {line}"
)))
}
};
Expand Down
Loading

0 comments on commit 68fbfc8

Please sign in to comment.