Skip to content

Commit ce5fd43

Browse files
authored
Move all unnecessary std uses to core,alloc (#3027)
* Move all unnecessary std uses to core,alloc * More * more fix * more * more * Remove libafl-fuzz grimoire * more * more * more cleanup * remove bins * fix * more fix
1 parent c7207dc commit ce5fd43

File tree

106 files changed

+1498
-1446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1498
-1446
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ program
7676
fuzzer_libpng*
7777

7878
*.patch
79+
80+
# Sometimes this happens
81+
rustc-ice-*

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ all = { level = "deny", priority = -1 }
148148
pedantic = { level = "deny", priority = -1 }
149149
cargo_common_metadata = "deny"
150150

151+
alloc_instead_of_core = "deny"
152+
std_instead_of_alloc = "deny"
153+
std_instead_of_core = "deny"
154+
151155
# Warn
152156
cargo = { level = "warn", priority = -1 }
153157

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
injection_test
2+
static

libafl/examples/tui_mock/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! An example for TUI that uses the TUI without any real data.
22
//! This is mainly to fix the UI without having to run a real fuzzer.
33
4-
use std::{thread::sleep, time::Duration};
4+
use core::time::Duration;
5+
use std::thread::sleep;
56

67
use libafl::monitors::{
78
Monitor,

libafl/src/common/nautilus/grammartec/chunkstore.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use alloc::{string::String, vec::Vec};
2-
use std::{
3-
fs::File,
4-
io::Write,
5-
sync::{RwLock, atomic::AtomicBool},
6-
};
2+
use core::sync::atomic::AtomicBool;
3+
use std::{fs::File, io::Write, sync::RwLock};
74

85
use hashbrown::{HashMap, HashSet};
96
use libafl_bolts::rands::Rand;

libafl/src/common/nautilus/grammartec/newtypes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ops::Add;
1+
use core::ops::Add;
22

33
use serde::{Deserialize, Serialize};
44

libafl/src/common/nautilus/grammartec/python_grammar_loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::useless_conversion)] // This seems to be a false-positive(?)
22

3-
use std::{ffi::CString, string::String, vec::Vec};
3+
use alloc::{ffi::CString, string::String, vec::Vec};
44

55
use pyo3::{prelude::*, pyclass, types::IntoPyDict};
66

libafl/src/common/nautilus/grammartec/recursion_info.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use alloc::vec::Vec;
2-
use std::fmt;
1+
use alloc::{fmt, vec::Vec};
32

43
use hashbrown::HashMap;
54
use libafl_bolts::{

libafl/src/common/nautilus/grammartec/rule.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static SPLITTER: OnceLock<regex::Regex> = OnceLock::new();
2525
static TOKENIZER: OnceLock<regex::bytes::Regex> = OnceLock::new();
2626

2727
fn show_bytes(bs: &[u8]) -> String {
28-
use std::{ascii::escape_default, str};
28+
use core::{ascii::escape_default, str};
2929

3030
let mut visible = String::new();
3131
for &b in bs {
@@ -265,7 +265,7 @@ impl Rule {
265265
if let Some(sub) = cap.get(1) {
266266
//println!("cap.get(1): {}", sub.as_str());
267267
RuleChild::from_nt(
268-
std::str::from_utf8(sub.as_bytes())
268+
core::str::from_utf8(sub.as_bytes())
269269
.expect("nonterminals need to be valid strings"),
270270
ctx,
271271
)

libafl/src/common/nautilus/grammartec/tree.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloc::vec::Vec;
2-
use std::{cmp, io, io::Write, marker::Sized};
2+
use core::{cmp, marker::Sized};
3+
use std::io::{Cursor, Write, stdout};
34

45
use hashbrown::HashSet;
56
use libafl_bolts::rands::Rand;
@@ -28,7 +29,7 @@ enum UnparseStep<'dat> {
2829
struct Unparser<'data, 'tree: 'data, 'ctx: 'data, W: Write, T: TreeLike> {
2930
tree: &'tree T,
3031
stack: Vec<UnparseStep<'data>>,
31-
buffers: Vec<io::Cursor<Vec<u8>>>,
32+
buffers: Vec<Cursor<Vec<u8>>>,
3233
w: W,
3334
i: usize,
3435
ctx: &'ctx Context,
@@ -81,10 +82,7 @@ impl<'data, 'tree: 'data, 'ctx: 'data, W: Write, T: TreeLike> Unparser<'data, 't
8182
}
8283
fn script(&mut self, py: Python, num: usize, expr: &PyObject) -> PyResult<()> {
8384
let bufs = self.buffers.split_off(self.buffers.len() - num);
84-
let bufs = bufs
85-
.into_iter()
86-
.map(io::Cursor::into_inner)
87-
.collect::<Vec<_>>();
85+
let bufs = bufs.into_iter().map(Cursor::into_inner).collect::<Vec<_>>();
8886
let byte_arrays = bufs.iter().map(|b| PyBytes::new(py, b));
8987
let res = expr.call1(py, PyTuple::new(py, byte_arrays)?)?;
9088
let bound = res.bind(py);
@@ -103,7 +101,7 @@ impl<'data, 'tree: 'data, 'ctx: 'data, W: Write, T: TreeLike> Unparser<'data, 't
103101
}
104102

105103
fn push_buffer(&mut self) {
106-
self.buffers.push(io::Cursor::new(vec![]));
104+
self.buffers.push(Cursor::new(vec![]));
107105
}
108106

109107
fn next_rule(&mut self, nt: NTermId) {
@@ -184,7 +182,7 @@ where
184182
}
185183

186184
fn unparse_print(&self, ctx: &Context) {
187-
self.unparse_to(ctx, &mut io::stdout());
185+
self.unparse_to(ctx, &mut stdout());
188186
}
189187
}
190188

libafl/src/common/nautilus/regex_mutator/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn append_unicode_range<R: Rand>(
5959
let a = u32::from_le_bytes(chr_a_buf);
6060
let b = u32::from_le_bytes(chr_b_buf);
6161
let c = scr.get_range(rand, a as usize, (b + 1) as usize) as u32;
62-
append_char(res, std::char::from_u32(c).unwrap());
62+
append_char(res, core::char::from_u32(c).unwrap());
6363
}
6464

6565
fn append_byte_range<R: Rand>(

libafl/src/events/broker_hooks/centralized_multi_machine.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use std::{
1+
use alloc::{sync::Arc, vec::Vec};
2+
use core::{
23
fmt::{Debug, Display},
34
marker::PhantomData,
45
slice,
5-
sync::Arc,
6-
vec::Vec,
76
};
87

98
#[cfg(feature = "llmp_compression")]

libafl/src/events/launcher.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
//! On `Unix` systems, the [`Launcher`] will use `fork` if the `fork` feature is used for `LibAFL`.
1313
//! Else, it will start subsequent nodes with the same commandline, and will set special `env` variables accordingly.
1414
15+
use alloc::string::String;
1516
use core::{
1617
fmt::{self, Debug, Formatter},
18+
net::SocketAddr,
1719
num::NonZeroUsize,
1820
time::Duration,
1921
};
20-
use std::{net::SocketAddr, string::String};
2122

2223
use libafl_bolts::{
2324
core_affinity::{CoreId, Cores},
@@ -32,13 +33,13 @@ use {
3233
events::{CentralizedLlmpHook, StdLlmpEventHook, centralized::CentralizedEventManager},
3334
inputs::Input,
3435
},
36+
alloc::boxed::Box,
3537
alloc::string::ToString,
3638
libafl_bolts::{
3739
core_affinity::get_core_ids,
3840
llmp::{Broker, Brokers, LlmpBroker},
3941
os::{ForkResult, fork},
4042
},
41-
std::boxed::Box,
4243
};
4344
#[cfg(unix)]
4445
use {

libafl/src/events/llmp/restarting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use alloc::string::ToString;
88
use alloc::vec::Vec;
99
use core::{
1010
marker::PhantomData,
11+
net::SocketAddr,
1112
num::NonZeroUsize,
1213
sync::atomic::{Ordering, compiler_fence},
1314
time::Duration,
1415
};
15-
use std::net::SocketAddr;
1616
#[cfg(feature = "std")]
1717
use std::net::TcpStream;
1818

libafl/src/events/multi_machine.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
use core::fmt::Display;
2-
use std::{
3-
boxed::Box,
4-
collections::HashMap,
5-
io::ErrorKind,
6-
process,
7-
sync::{
8-
Arc, OnceLock,
9-
atomic::{AtomicU64, Ordering},
10-
},
1+
use alloc::{boxed::Box, sync::Arc, vec::Vec};
2+
use core::{
3+
fmt::Display,
4+
sync::atomic::{AtomicU64, Ordering},
115
time::Duration,
12-
vec::Vec,
136
};
7+
use std::{collections::HashMap, io::ErrorKind, process, sync::OnceLock};
148

159
use enumflags2::{BitFlags, bitflags};
1610
#[cfg(feature = "llmp_compression")]
@@ -407,9 +401,9 @@ where
407401

408402
/// Write an [`OwnedTcpMultiMachineMsg`] to a stream.
409403
/// Can be read back using [`TcpMultiMachineState::read_msg`].
410-
async fn write_msg<'a, I: Input>(
404+
async fn write_msg<I: Input>(
411405
stream: &mut TcpStream,
412-
msg: &MultiMachineMsg<'a, I>,
406+
msg: &MultiMachineMsg<'_, I>,
413407
) -> Result<(), Error> {
414408
let serialized_msg = msg.serialize_as_ref();
415409
let msg_len = u32::to_le_bytes(serialized_msg.len() as u32);
@@ -451,9 +445,9 @@ where
451445
Ok(())
452446
}
453447

454-
pub(crate) async fn send_interesting_event_to_nodes<'a, I: Input>(
448+
pub(crate) async fn send_interesting_event_to_nodes<I: Input>(
455449
&mut self,
456-
msg: &MultiMachineMsg<'a, I>,
450+
msg: &MultiMachineMsg<'_, I>,
457451
) -> Result<(), Error> {
458452
log::debug!("Sending interesting events to nodes...");
459453

@@ -503,9 +497,9 @@ where
503497

504498
/// Flush the message queue from other nodes and add incoming events to the
505499
/// centralized event manager queue.
506-
pub(crate) async fn receive_new_messages_from_nodes<'a, I: Input>(
500+
pub(crate) async fn receive_new_messages_from_nodes<I: Input>(
507501
&mut self,
508-
msgs: &mut Vec<MultiMachineMsg<'a, I>>,
502+
msgs: &mut Vec<MultiMachineMsg<'_, I>>,
509503
) -> Result<(), Error> {
510504
log::debug!("Checking for new events from other nodes...");
511505
// let mut nb_received = 0usize;

libafl/src/events/tcp.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//! TCP-backed event manager for scalable multi-processed fuzzing
22
3-
use alloc::vec::Vec;
3+
use alloc::{sync::Arc, vec::Vec};
44
use core::{
55
marker::PhantomData,
6+
net::SocketAddr,
67
num::NonZeroUsize,
78
sync::atomic::{Ordering, compiler_fence},
89
time::Duration,
910
};
1011
use std::{
1112
env,
1213
io::{ErrorKind, Read, Write},
13-
net::{SocketAddr, TcpListener, TcpStream, ToSocketAddrs},
14-
sync::Arc,
14+
net::{TcpListener, TcpStream, ToSocketAddrs},
1515
};
1616

1717
#[cfg(feature = "tcp_compression")]

libafl/src/executors/command.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
//! The command executor executes a sub program for each run
2+
#[cfg(all(feature = "intel_pt", target_os = "linux"))]
3+
use alloc::ffi::CString;
24
use alloc::vec::Vec;
5+
#[cfg(all(feature = "intel_pt", target_os = "linux"))]
6+
use core::ffi::CStr;
37
use core::{
48
fmt::{self, Debug, Formatter},
59
marker::PhantomData,
610
ops::IndexMut,
11+
time::Duration,
712
};
813
#[cfg(all(feature = "intel_pt", target_os = "linux"))]
9-
use std::{
10-
ffi::{CStr, CString},
11-
os::fd::AsRawFd,
12-
};
14+
use std::os::fd::AsRawFd;
1315
use std::{
1416
ffi::{OsStr, OsString},
1517
io::{Read, Write},
1618
os::unix::ffi::OsStrExt,
1719
path::{Path, PathBuf},
1820
process::{Child, Command, Stdio},
19-
time::Duration,
2021
};
2122

2223
#[cfg(all(feature = "intel_pt", target_os = "linux"))]

libafl/src/executors/hooks/inprocess.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl InProcessExecutorHandlerData {
464464
);
465465

466466
if let Ok(bsod) = bsod {
467-
if let Ok(r) = std::str::from_utf8(&bsod) {
467+
if let Ok(r) = core::str::from_utf8(&bsod) {
468468
log::error!("{}", r);
469469
}
470470
}

libafl/src/executors/hooks/unix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub mod unix_signal_handler {
238238
}
239239
let _ = writer.flush();
240240
}
241-
if let Ok(r) = std::str::from_utf8(&bsod) {
241+
if let Ok(r) = core::str::from_utf8(&bsod) {
242242
log::error!("{}", r);
243243
}
244244
}
@@ -278,7 +278,7 @@ pub mod unix_signal_handler {
278278
}
279279
let _ = writer.flush();
280280
}
281-
if let Ok(r) = std::str::from_utf8(&bsod) {
281+
if let Ok(r) = core::str::from_utf8(&bsod) {
282282
log::error!("{}", r);
283283
}
284284
}

libafl/src/feedbacks/capture_feedback.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Feedback that captures Timeouts for re-running
2-
use std::{borrow::Cow, cell::RefCell, fmt::Debug, rc::Rc};
2+
use alloc::{borrow::Cow, rc::Rc};
3+
use core::{cell::RefCell, fmt::Debug};
34

45
use libafl_bolts::{Error, Named};
56
use serde::{Serialize, de::DeserializeOwned};

libafl/src/feedbacks/nautilus.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct NautilusChunksMetadata {
2525
}
2626

2727
impl Debug for NautilusChunksMetadata {
28-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2929
write!(
3030
f,
3131
"NautilusChunksMetadata {{ {} }}",

libafl/src/feedbacks/new_hash_feedback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! The [`NewHashFeedback`] uses the backtrace hash and a hashset to only keep novel cases
22
33
use alloc::{borrow::Cow, string::ToString};
4-
use std::fmt::Debug;
4+
use core::fmt::Debug;
55

66
use hashbrown::HashSet;
77
use libafl_bolts::{

libafl/src/fuzzer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! The `Fuzzer` is the main struct for a fuzz campaign.
22
33
use alloc::{string::ToString, vec::Vec};
4-
use core::{fmt::Debug, time::Duration};
54
#[cfg(feature = "std")]
6-
use std::hash::Hash;
5+
use core::hash::Hash;
6+
use core::{fmt::Debug, time::Duration};
77

88
#[cfg(feature = "std")]
99
use fastbloom::BloomFilter;

libafl/src/generators/nautilus.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct NautilusContext {
2121
}
2222

2323
impl Debug for NautilusContext {
24-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2525
write!(f, "NautilusContext {{}}",)
2626
}
2727
}
@@ -114,7 +114,7 @@ pub struct NautilusGenerator<'a> {
114114
}
115115

116116
impl Debug for NautilusGenerator<'_> {
117-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
117+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
118118
write!(f, "NautilusGenerator {{}}",)
119119
}
120120
}

libafl/src/inputs/multi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! An input composed of multiple parts identified by a key.
22
3-
use alloc::{fmt::Debug, string::String, vec::Vec};
4-
use core::hash::Hash;
3+
use alloc::{string::String, vec::Vec};
4+
use core::{fmt::Debug, hash::Hash};
55

66
use serde::{Serialize, de::DeserializeOwned};
77

0 commit comments

Comments
 (0)