Skip to content

Commit 68fbfc8

Browse files
domenukktokatoka
andauthored
Fix Clippy (#926)
* 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 <[email protected]>
1 parent ee58375 commit 68fbfc8

File tree

26 files changed

+86
-142
lines changed

26 files changed

+86
-142
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ __pycache__
5151
**/libxml2
5252
**/corpus_discovered
5353
**/libxml2-*.tar.gz
54+
55+
libafl_nyx/QEMU-Nyx
56+
libafl_nyx/packer

libafl/examples/llmp_test/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ fn adder_loop(port: u16) -> ! {
4848
}
4949

5050
if current_result != last_result {
51-
println!(
52-
"Adder handled {} messages, reporting {} to broker",
53-
msg_counter, current_result
54-
);
51+
println!("Adder handled {msg_counter} messages, reporting {current_result} to broker");
5552

5653
client
5754
.send_buf(_TAG_MATH_RESULT_V1, &current_result.to_le_bytes())

libafl/src/bolts/core_affinity.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ impl Cores {
132132

133133
if cores.is_empty() {
134134
return Err(Error::illegal_argument(format!(
135-
"No cores specified! parsed: {}",
136-
args
135+
"No cores specified! parsed: {args}"
137136
)));
138137
}
139138

@@ -591,8 +590,7 @@ mod apple {
591590
Ok(())
592591
} else {
593592
Err(Error::unknown(format!(
594-
"Failed to set_for_current {:?}",
595-
result
593+
"Failed to set_for_current {result:?}"
596594
)))
597595
}
598596
}
@@ -615,8 +613,7 @@ mod apple {
615613
Ok(())
616614
} else {
617615
Err(Error::unknown(format!(
618-
"Failed to set_for_current {:?}",
619-
result
616+
"Failed to set_for_current {result:?}"
620617
)))
621618
}
622619
}

libafl/src/bolts/llmp.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,7 @@ unsafe fn _llmp_page_init<SHM: ShMem>(shmem: &mut SHM, sender_id: ClientId, allo
466466
if !allow_reinit {
467467
assert!(
468468
(*page).magic != PAGE_INITIALIZED_MAGIC,
469-
"Tried to initialize page {:?} twice (for shmem {:?})",
470-
page,
471-
shmem
469+
"Tried to initialize page {page:?} twice (for shmem {shmem:?})"
472470
);
473471
}
474472

@@ -641,10 +639,7 @@ where
641639
}
642640
Err(Error::File(e, _)) if e.kind() == ErrorKind::AddrInUse => {
643641
// We are the client :)
644-
println!(
645-
"We're the client (internal port already bound by broker, {:#?})",
646-
e
647-
);
642+
println!("We're the client (internal port already bound by broker, {e:#?})");
648643
Ok(LlmpConnection::IsClient {
649644
client: LlmpClient::create_attach_to_tcp(shmem_provider, port)?,
650645
})
@@ -1082,8 +1077,7 @@ where
10821077
let page = self.out_shmems.last_mut().unwrap().page_mut();
10831078
if msg.is_null() || !llmp_msg_in_page(page, msg) {
10841079
return Err(Error::unknown(format!(
1085-
"Llmp Message {:?} is null or not in current page",
1086-
msg
1080+
"Llmp Message {msg:?} is null or not in current page"
10871081
)));
10881082
}
10891083

@@ -1189,8 +1183,7 @@ where
11891183
match unsafe { self.alloc_next_if_space(buf_len) } {
11901184
Some(msg) => Ok(msg),
11911185
None => Err(Error::unknown(format!(
1192-
"Error allocating {} bytes in shmap",
1193-
buf_len
1186+
"Error allocating {buf_len} bytes in shmap"
11941187
))),
11951188
}
11961189
}
@@ -1258,8 +1251,7 @@ where
12581251
|| tag == LLMP_TAG_UNSET
12591252
{
12601253
return Err(Error::unknown(format!(
1261-
"Reserved tag supplied to send_buf ({:#X})",
1262-
tag
1254+
"Reserved tag supplied to send_buf ({tag:#X})"
12631255
)));
12641256
}
12651257

@@ -1282,8 +1274,7 @@ where
12821274
|| tag == LLMP_TAG_UNSET
12831275
{
12841276
return Err(Error::unknown(format!(
1285-
"Reserved tag supplied to send_buf ({:#X})",
1286-
tag
1277+
"Reserved tag supplied to send_buf ({tag:#X})"
12871278
)));
12881279
}
12891280

@@ -1742,8 +1733,7 @@ where
17421733
let page_size = self.shmem.as_slice().len() - size_of::<LlmpPage>();
17431734
if offset > page_size {
17441735
Err(Error::illegal_argument(format!(
1745-
"Msg offset out of bounds (size: {}, requested offset: {})",
1746-
page_size, offset
1736+
"Msg offset out of bounds (size: {page_size}, requested offset: {offset})"
17471737
)))
17481738
} else {
17491739
unsafe { Ok(((*page).messages.as_mut_ptr() as *mut u8).add(offset) as *mut LlmpMsg) }
@@ -2048,7 +2038,7 @@ where
20482038
/// This function returns the [`ShMemDescription`] the client uses to place incoming messages.
20492039
/// The thread exits, when the remote broker disconnects.
20502040
#[cfg(feature = "std")]
2051-
#[allow(clippy::let_and_return)]
2041+
#[allow(clippy::let_and_return, clippy::too_many_lines)]
20522042
fn b2b_thread_on(
20532043
mut stream: TcpStream,
20542044
b2b_client_id: ClientId,
@@ -2106,8 +2096,7 @@ where
21062096
Ok(Some((client_id, tag, flags, payload))) => {
21072097
if client_id == b2b_client_id {
21082098
println!(
2109-
"Ignored message we probably sent earlier (same id), TAG: {:x}",
2110-
tag
2099+
"Ignored message we probably sent earlier (same id), TAG: {tag:x}"
21112100
);
21122101
continue;
21132102
}
@@ -2127,15 +2116,15 @@ where
21272116
payload: payload.to_vec(),
21282117
},
21292118
) {
2130-
println!("Got error {} while trying to forward a message to broker {}, exiting thread", e, peer_address);
2119+
println!("Got error {e} while trying to forward a message to broker {peer_address}, exiting thread");
21312120
return;
21322121
}
21332122
}
21342123
Err(Error::ShuttingDown) => {
21352124
println!("Local broker is shutting down, exiting thread");
21362125
return;
21372126
}
2138-
Err(e) => panic!("Error reading from local page! {}", e),
2127+
Err(e) => panic!("Error reading from local page! {e}"),
21392128
}
21402129
}
21412130

@@ -2171,8 +2160,7 @@ where
21712160
if let Error::File(e, _) = e {
21722161
if e.kind() == ErrorKind::UnexpectedEof {
21732162
println!(
2174-
"Broker {} seems to have disconnected, exiting",
2175-
peer_address
2163+
"Broker {peer_address} seems to have disconnected, exiting"
21762164
);
21772165
return;
21782166
}
@@ -2417,8 +2405,7 @@ where
24172405
println!("Error adding client! Ignoring: {e:?}");
24182406
#[cfg(not(feature = "std"))]
24192407
return Err(Error::unknown(format!(
2420-
"Error adding client! PANIC! {:?}",
2421-
e
2408+
"Error adding client! PANIC! {e:?}"
24222409
)));
24232410
}
24242411
};

libafl/src/bolts/os/unix_signals.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ pub unsafe fn setup_signal_handler<T: 'static + Handler>(handler: &mut T) -> Res
391391
// Rust always panics on OOM, so we will, too.
392392
assert!(
393393
!SIGNAL_STACK_PTR.is_null(),
394-
"Failed to allocate signal stack with {} bytes!",
395-
SIGNAL_STACK_SIZE
394+
"Failed to allocate signal stack with {SIGNAL_STACK_SIZE} bytes!"
396395
);
397396
}
398397
let mut ss: stack_t = mem::zeroed();

libafl/src/bolts/shmem.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ where
468468
Ok(())
469469
} else {
470470
Err(Error::unknown(format!(
471-
"Wrong result read from pipe! Expected 0, got {:?}",
472-
ret
471+
"Wrong result read from pipe! Expected 0, got {ret:?}"
473472
)))
474473
}
475474
}
@@ -630,8 +629,7 @@ pub mod unix_shmem {
630629
if shm_fd == -1 {
631630
perror(b"shm_open\0".as_ptr() as *const _);
632631
return Err(Error::unknown(format!(
633-
"Failed to shm_open map with id {:?}",
634-
shmem_ctr
632+
"Failed to shm_open map with id {shmem_ctr:?}"
635633
)));
636634
}
637635

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

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

@@ -691,8 +687,7 @@ pub mod unix_shmem {
691687
perror(b"mmap\0".as_ptr() as *const _);
692688
close(shm_fd);
693689
return Err(Error::unknown(format!(
694-
"mmap() failed for map with fd {:?}",
695-
shm_fd
690+
"mmap() failed for map with fd {shm_fd:?}"
696691
)));
697692
}
698693

@@ -997,8 +992,7 @@ pub mod unix_shmem {
997992
let fd = open(device_path.as_ptr(), O_RDWR);
998993
if fd == -1 {
999994
return Err(Error::unknown(format!(
1000-
"Failed to open the ashmem device at {:?}",
1001-
device_path
995+
"Failed to open the ashmem device at {device_path:?}"
1002996
)));
1003997
}
1004998

libafl/src/events/llmp.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,7 @@ where
398398
executions: _,
399399
} => {
400400
#[cfg(feature = "std")]
401-
println!(
402-
"Received new Testcase from {} ({:?})",
403-
_client_id, client_config
404-
);
401+
println!("Received new Testcase from {_client_id} ({client_config:?})");
405402

406403
let _res = if client_config.match_with(&self.configuration)
407404
&& observers_buf.is_some()
@@ -890,8 +887,13 @@ where
890887
mgr.to_env(_ENV_FUZZER_BROKER_CLIENT_INITIAL);
891888

892889
// First, create a channel from the current fuzzer to the next to store state between restarts.
890+
#[cfg(unix)]
893891
let mut staterestorer: StateRestorer<SP> =
894892
StateRestorer::new(self.shmem_provider.new_shmem(256 * 1024 * 1024)?);
893+
894+
#[cfg(not(unix))]
895+
let staterestorer: StateRestorer<SP> =
896+
StateRestorer::new(self.shmem_provider.new_shmem(256 * 1024 * 1024)?);
895897
// Store the information to a map.
896898
staterestorer.write_to_env(_ENV_FUZZER_SENDER)?;
897899

libafl/src/events/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pub static mut SHUTDOWN_SIGHANDLER_DATA: ShutdownSignalData = ShutdownSignalData
4141
shutdown_handler: core::ptr::null(),
4242
};
4343

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

5959
/// Shutdown handler. `SigTerm`, `SigInterrupt`, `SigQuit` call this
6060
/// 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
61+
///
62+
/// # Safety
63+
///
64+
/// This will acceess `data` and write to the global `data.staterestorer_ptr` if it's not null.
6165
#[cfg(all(unix, feature = "std"))]
6266
pub unsafe fn shutdown_handler<SP>(
6367
signal: Signal,

libafl/src/events/simple.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ where
292292
Ok(())
293293
} else {
294294
Err(Error::unknown(format!(
295-
"Received illegal message that message should not have arrived: {:?}.",
296-
event
295+
"Received illegal message that message should not have arrived: {event:?}."
297296
)))
298297
}
299298
}
@@ -445,8 +444,13 @@ where
445444
// We start ourself as child process to actually fuzz
446445
let mut staterestorer = if std::env::var(_ENV_FUZZER_SENDER).is_err() {
447446
// First, create a place to store state in, for restarts.
447+
#[cfg(unix)]
448+
let mut staterestorer: StateRestorer<SP> =
449+
StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?);
450+
#[cfg(not(unix))]
448451
let staterestorer: StateRestorer<SP> =
449452
StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?);
453+
450454
//let staterestorer = { LlmpSender::new(shmem_provider.clone(), 0, false)? };
451455
staterestorer.write_to_env(_ENV_FUZZER_SENDER)?;
452456

libafl/src/executors/forkserver.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ impl Forkserver {
249249
Ok(_) => (),
250250
Err(err) => {
251251
return Err(Error::illegal_state(format!(
252-
"Could not spawn the forkserver: {:#?}",
253-
err
252+
"Could not spawn the forkserver: {err:#?}"
254253
)))
255254
}
256255
};

libafl/src/executors/inprocess.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,7 @@ mod unix_signal_handler {
845845
let si_addr = { _info.si_addr() as usize };
846846

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

852851
#[cfg(all(feature = "std", unix))]

libafl/src/feedbacks/differential.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ where
7575
let o2_name = o2.name().to_string();
7676
if o1_name == o2_name {
7777
Err(Error::illegal_argument(format!(
78-
"DiffFeedback: observer names must be different (both were {})",
79-
o1_name
78+
"DiffFeedback: observer names must be different (both were {o1_name})"
8079
)))
8180
} else {
8281
Ok(Self {

libafl/src/monitors/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,7 @@ impl core::fmt::Display for ClientPerfMonitor {
832832
// Create the formatted string
833833
writeln!(
834834
f,
835-
" {:6.4}: Scheduler\n {:6.4}: Manager",
836-
scheduler_percent, manager_percent
835+
" {scheduler_percent:6.4}: Scheduler\n {manager_percent:6.4}: Manager"
837836
)?;
838837

839838
// Calculate each stage

libafl/src/mutators/token_mutations.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ impl Tokens {
113113
}
114114
if token_stop < token_start {
115115
return Err(Error::illegal_argument(format!(
116-
"Tried to create tokens from illegal section: stop < start ({:?} < {:?})",
117-
token_stop, token_start
116+
"Tried to create tokens from illegal section: stop < start ({token_stop:?} < {token_start:?})"
118117
)));
119118
}
120119
let section_size: usize = token_stop.offset_from(token_start).try_into().unwrap();
@@ -185,8 +184,7 @@ impl Tokens {
185184
Ok(val) => val,
186185
Err(_) => {
187186
return Err(Error::illegal_argument(format!(
188-
"Illegal line (hex decoding): {}",
189-
line
187+
"Illegal line (hex decoding): {line}"
190188
)))
191189
}
192190
};

0 commit comments

Comments
 (0)