From e89e8dbaabc9f840cdb3f4ebac3e8c5cfaf2d9f1 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Thu, 24 Aug 2023 11:34:38 +0200 Subject: [PATCH] Remove dependencies, add doc.rs metadata (#1450) * Remove dependency, add doc.rs metadata * remove lazy_static * even less lazy_static * serial_test no default --- fuzzers/baby_fuzzer_gramatron/Cargo.toml | 2 +- libafl/Cargo.toml | 5 +- libafl/src/feedbacks/new_hash_feedback.rs | 1 + libafl/src/observers/concolic/metadata.rs | 1 + libafl_bolts/Cargo.toml | 10 +-- libafl_bolts/src/build_id.rs | 5 +- libafl_concolic/symcc_libafl/Cargo.toml | 3 + libafl_concolic/symcc_runtime/Cargo.toml | 8 ++- libafl_concolic/symcc_runtime/build.rs | 62 ++++++++++--------- libafl_frida/Cargo.toml | 5 +- libafl_qemu/Cargo.toml | 3 + libafl_qemu/libafl_qemu_build/Cargo.toml | 3 + libafl_qemu/libafl_qemu_sys/Cargo.toml | 3 + libafl_sugar/Cargo.toml | 3 + libafl_targets/Cargo.toml | 3 + utils/gramatron/construct_automata/Cargo.toml | 5 +- .../gramatron/construct_automata/src/main.rs | 10 +-- 17 files changed, 84 insertions(+), 48 deletions(-) diff --git a/fuzzers/baby_fuzzer_gramatron/Cargo.toml b/fuzzers/baby_fuzzer_gramatron/Cargo.toml index 9cb567f2e6..26b03e6e5e 100644 --- a/fuzzers/baby_fuzzer_gramatron/Cargo.toml +++ b/fuzzers/baby_fuzzer_gramatron/Cargo.toml @@ -21,4 +21,4 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } libafl_bolts = { path = "../../libafl_bolts/" } -postcard = "0.7" +postcard = { version = "1.0", features = ["alloc"], default-features = false } # no_std compatible serde serialization format \ No newline at end of file diff --git a/libafl/Cargo.toml b/libafl/Cargo.toml index ff2afac779..78c1e3ff49 100644 --- a/libafl/Cargo.toml +++ b/libafl/Cargo.toml @@ -11,6 +11,9 @@ keywords = ["fuzzing", "testing", "security"] edition = "2021" categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"] +[package.metadata.docs.rs] +all-features = true + [features] default = ["std", "derive", "llmp_compression", "llmp_small_maps", "llmp_broker_timeouts", "rand_trait", "fork", "prelude", "gzip", "regex", "serdeany_autoreg", "tui_monitor"] std = ["serde_json", "serde_json/std", "nix", "serde/std", "bincode", "wait-timeout", "uuid", "backtrace", "serial_test", "libafl_bolts/std", "typed-builder"] # print, env, launcher ... support @@ -102,7 +105,7 @@ concat-idents = { version = "1.1.3", optional = true } libcasr = { version = "2.7", optional = true} # optional-dev deps (change when target.'cfg(accessible(::std))'.test-dependencies will be stable) -serial_test = { version = "2", optional = true } +serial_test = { version = "2", optional = true, default-features = false, features = ["logging"] } # AGPL # !!! this create requires nightly diff --git a/libafl/src/feedbacks/new_hash_feedback.rs b/libafl/src/feedbacks/new_hash_feedback.rs index 01833754ba..f326198e29 100644 --- a/libafl/src/feedbacks/new_hash_feedback.rs +++ b/libafl/src/feedbacks/new_hash_feedback.rs @@ -30,6 +30,7 @@ pub trait HashSetState { /// The state of [`NewHashFeedback`] #[derive(Default, Serialize, Deserialize, Clone, Debug)] +#[allow(clippy::unsafe_derive_deserialize)] pub struct NewHashFeedbackMetadata { /// Contains information about untouched entries pub hash_set: HashSet, diff --git a/libafl/src/observers/concolic/metadata.rs b/libafl/src/observers/concolic/metadata.rs index ceb490bc11..cb9d34a795 100644 --- a/libafl/src/observers/concolic/metadata.rs +++ b/libafl/src/observers/concolic/metadata.rs @@ -6,6 +6,7 @@ use crate::observers::concolic::{serialization_format::MessageFileReader, SymExp /// A metadata holding a buffer of a concolic trace. #[derive(Default, Serialize, Deserialize, Debug)] +#[allow(clippy::unsafe_derive_deserialize)] pub struct ConcolicMetadata { /// Constraints data buffer: Vec, diff --git a/libafl_bolts/Cargo.toml b/libafl_bolts/Cargo.toml index f006168f02..ed411254f2 100644 --- a/libafl_bolts/Cargo.toml +++ b/libafl_bolts/Cargo.toml @@ -11,9 +11,12 @@ keywords = ["fuzzing", "testing", "security"] edition = "2021" categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"] +[package.metadata.docs.rs] +all-features = true + [features] default = ["std", "derive", "llmp_compression", "llmp_small_maps", "rand_trait", "prelude", "gzip", "serdeany_autoreg", "alloc"] -std = ["serde_json", "serde_json/std", "hostname", "nix", "serde/std", "uuid", "byteorder", "backtrace", "uds", "serial_test", "alloc"] # print, env, ... support +std = ["serde_json", "serde_json/std", "hostname", "nix", "serde/std", "uuid", "backtrace", "uds", "serial_test", "alloc"] # print, env, ... support alloc = ["serde/alloc", "hashbrown", "postcard", "erased-serde/alloc", "ahash"] # Enables all features that allocate in no_std derive = ["libafl_derive"] # provide derive(SerdeAny) macro. rand_trait = ["rand_core"] # If set, libafl's rand implementations will implement `rand::Rng` @@ -62,18 +65,17 @@ hostname = { version = "^0.3", optional = true } # Is there really no gethostnam rand_core = { version = "0.6", optional = true } nix = { version = "0.26", optional = true } uuid = { version = "1.4", optional = true, features = ["serde", "v4"] } -byteorder = { version = "1.4", optional = true } clap = {version = "4.0", features = ["derive", "wrap_help"], optional = true} # CLI parsing, for libafl_bolts::cli / the `cli` feature log = "0.4.20" pyo3 = { version = "0.18.3", optional = true, features = ["serde", "macros"] } # optional-dev deps (change when target.'cfg(accessible(::std))'.test-dependencies will be stable) -serial_test = { version = "2", optional = true } +serial_test = { version = "2", optional = true, default-features = false, features = ["logging"] } [target.'cfg(unix)'.dependencies] libc = "0.2" # For (*nix) libc -uds = { version = "0.4", optional = true, default_features = false } +uds = { version = "0.4", optional = true, default-features = false } [target.'cfg(windows)'.dependencies] windows = { version = "0.51.1", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_System_Diagnostics_Debug", "Win32_System_Kernel", "Win32_System_Memory", "Win32_Security", "Win32_System_SystemInformation"] } diff --git a/libafl_bolts/src/build_id.rs b/libafl_bolts/src/build_id.rs index d9e2433e13..ab1229331c 100644 --- a/libafl_bolts/src/build_id.rs +++ b/libafl_bolts/src/build_id.rs @@ -87,9 +87,10 @@ fn calculate() -> Uuid { let mut hasher = from_type_id(hasher); let mut bytes = [0; 16]; - ::write_u64(&mut bytes[..8], hasher.finish()); + bytes[..8].copy_from_slice(&hasher.finish().to_ne_bytes()); + hasher.write_u8(0); - ::write_u64(&mut bytes[8..], hasher.finish()); + bytes[8..].copy_from_slice(&hasher.finish().to_ne_bytes()); *uuid::Builder::from_bytes(bytes) .set_variant(uuid::Variant::RFC4122) diff --git a/libafl_concolic/symcc_libafl/Cargo.toml b/libafl_concolic/symcc_libafl/Cargo.toml index e760b9b48a..cc0d6e3dc1 100644 --- a/libafl_concolic/symcc_libafl/Cargo.toml +++ b/libafl_concolic/symcc_libafl/Cargo.toml @@ -13,6 +13,9 @@ categories = ["development-tools::testing", "emulators", "embedded", "os", "no-s # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[package.metadata.docs.rs] +all-features = true + [features] default = ["build", "clone"] build = ["which", "cmake"] # common functionality to build symcc diff --git a/libafl_concolic/symcc_runtime/Cargo.toml b/libafl_concolic/symcc_runtime/Cargo.toml index b45d87c343..c34feaaecf 100644 --- a/libafl_concolic/symcc_runtime/Cargo.toml +++ b/libafl_concolic/symcc_runtime/Cargo.toml @@ -14,6 +14,9 @@ categories = ["development-tools::testing", "emulators", "embedded", "os", "no-s # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[package.metadata.docs.rs] +all-features = true + [features] # skips building and linking the C++ part of the runtime no-cpp-runtime = [] @@ -22,13 +25,12 @@ no-cpp-runtime = [] unchecked_unwrap = "4" ctor = "0.2" libc = "0.2" -libafl = { path = "../../libafl", version = "0.10.1", default-features=false, features=["std"] } -libafl_bolts = { path = "../../libafl_bolts", version = "0.10.1", default-features=false, features=["std"] } +libafl = { path = "../../libafl", version = "0.10.1", default-features=false, features=["std", "serdeany_autoreg"] } +libafl_bolts = { path = "../../libafl_bolts", version = "0.10.1", default-features=false, features=["std", "serdeany_autoreg"] } [build-dependencies] cmake = "0.1" bindgen = "0.63" regex = "1" -lazy_static = "1.4" which = "4.4" symcc_libafl = { path = "../symcc_libafl", version = "0.10.1" } diff --git a/libafl_concolic/symcc_runtime/build.rs b/libafl_concolic/symcc_runtime/build.rs index 0d825fc445..21cc9c35ed 100644 --- a/libafl_concolic/symcc_runtime/build.rs +++ b/libafl_concolic/symcc_runtime/build.rs @@ -1,4 +1,5 @@ use std::{ + cell::RefCell, env, fs::File, io::Write, @@ -6,18 +7,17 @@ use std::{ process::exit, }; -use lazy_static::lazy_static; use regex::{Regex, RegexBuilder}; use symcc_libafl::clone_symcc; const SYMCC_RUNTIME_FUNCTION_NAME_PREFIX: &str = "_cpp_"; -lazy_static! { - static ref FUNCTION_NAME_REGEX: Regex = Regex::new(r"pub fn (\w+)").unwrap(); - static ref EXPORTED_FUNCTION_REGEX: Regex = RegexBuilder::new(r"(pub fn \w+\([^\)]*\)[^;]*);") +thread_local! { + static FUNCTION_NAME_REGEX: RefCell = RefCell::new(Regex::new(r"pub fn (\w+)").unwrap()); + static EXPORTED_FUNCTION_REGEX: RefCell = RefCell::new(RegexBuilder::new(r"(pub fn \w+\([^\)]*\)[^;]*);") .multi_line(true) .build() - .unwrap(); + .unwrap()); } fn main() { @@ -88,16 +88,18 @@ fn write_cpp_function_export_macro(out_path: &Path, cpp_bindings: &bindgen::Bind () => {{", ) .unwrap(); - EXPORTED_FUNCTION_REGEX - .captures_iter(&cpp_bindings.to_string()) - .for_each(|captures| { - writeln!( - macro_file, - " symcc_runtime::export_c_symbol!({});", - &captures[1] - ) - .unwrap(); - }); + EXPORTED_FUNCTION_REGEX.with(|x| { + x.borrow() + .captures_iter(&cpp_bindings.to_string()) + .for_each(|captures| { + writeln!( + macro_file, + " symcc_runtime::export_c_symbol!({});", + &captures[1] + ) + .unwrap(); + }); + }); writeln!( macro_file, " }}; @@ -156,17 +158,21 @@ fn write_rust_runtime_macro_file(out_path: &Path, symcc_src_path: &Path) { ($macro:path; $($extra_ident:path),*) => {{", ) .unwrap(); - EXPORTED_FUNCTION_REGEX - .captures_iter(&rust_bindings.to_string()) - .for_each(|captures| { - writeln!( - rust_runtime_macro, - " $macro!({},{}; $($extra_ident),*);", - &captures[1].replace("_rsym_", ""), - &FUNCTION_NAME_REGEX.captures(&captures[1]).unwrap()[1] - ) - .unwrap(); - }); + EXPORTED_FUNCTION_REGEX.with(|x| { + x.borrow() + .captures_iter(&rust_bindings.to_string()) + .for_each(|captures| { + writeln!( + rust_runtime_macro, + " $macro!({},{}; $($extra_ident),*);", + &captures[1].replace("_rsym_", ""), + &FUNCTION_NAME_REGEX + .with(|x| x.borrow().captures(&captures[1])) + .unwrap()[1] + ) + .unwrap(); + }); + }); writeln!( rust_runtime_macro, " }}; @@ -178,7 +184,7 @@ fn write_rust_runtime_macro_file(out_path: &Path, symcc_src_path: &Path) { fn write_symcc_runtime_bindings_file(out_path: &Path, cpp_bindings: &bindgen::Bindings) { let mut bindings_file = File::create(out_path.join("bindings.rs")).unwrap(); cpp_bindings.to_string().lines().for_each(|l| { - if let Some(captures) = FUNCTION_NAME_REGEX.captures(l) { + if let Some(captures) = FUNCTION_NAME_REGEX.with(|x| x.borrow().captures(l)) { let function_name = &captures[1]; writeln!( bindings_file, @@ -202,7 +208,7 @@ fn write_symcc_rename_header(rename_header_path: &Path, cpp_bindings: &bindgen:: cpp_bindings .to_string() .lines() - .filter_map(|l| FUNCTION_NAME_REGEX.captures(l)) + .filter_map(|l| FUNCTION_NAME_REGEX.with(|x| x.borrow().captures(l))) .map(|captures| captures[1].to_string()) .for_each(|val| { writeln!( diff --git a/libafl_frida/Cargo.toml b/libafl_frida/Cargo.toml index 439635fea7..18841251ef 100644 --- a/libafl_frida/Cargo.toml +++ b/libafl_frida/Cargo.toml @@ -17,6 +17,9 @@ categories = [ "no-std" ] +[package.metadata.docs.rs] +all-features = true + [features] default = ["serdeany_autoreg"] cmplog = [] @@ -71,4 +74,4 @@ paste = "1.0" log = "0.4.20" [dev-dependencies] -serial_test = "1" +serial_test = { version = "2", default-features = false, features = ["logging"] } diff --git a/libafl_qemu/Cargo.toml b/libafl_qemu/Cargo.toml index 19bfc62b47..a9c945a5f6 100644 --- a/libafl_qemu/Cargo.toml +++ b/libafl_qemu/Cargo.toml @@ -11,6 +11,9 @@ keywords = ["fuzzing", "qemu", "instrumentation"] edition = "2021" categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"] +[package.metadata.docs.rs] +all-features = true + [features] default = ["fork", "build_libqasan", "serdeany_autoreg"] python = ["pyo3", "pyo3-build-config"] diff --git a/libafl_qemu/libafl_qemu_build/Cargo.toml b/libafl_qemu/libafl_qemu_build/Cargo.toml index e98def0c6e..fbde0ea970 100644 --- a/libafl_qemu/libafl_qemu_build/Cargo.toml +++ b/libafl_qemu/libafl_qemu_build/Cargo.toml @@ -17,6 +17,9 @@ categories = [ "no-std", ] +[package.metadata.docs.rs] +all-features = true + [features] slirp = [] # build qemu with host libslirp (for user networking) diff --git a/libafl_qemu/libafl_qemu_sys/Cargo.toml b/libafl_qemu/libafl_qemu_sys/Cargo.toml index d3bd59f4f2..b0390d0f9e 100644 --- a/libafl_qemu/libafl_qemu_sys/Cargo.toml +++ b/libafl_qemu/libafl_qemu_sys/Cargo.toml @@ -11,6 +11,9 @@ keywords = ["fuzzing", "qemu", "instrumentation"] edition = "2021" categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"] +[package.metadata.docs.rs] +all-features = true + [features] # The following architecture features are mutually exclusive. x86_64 = [] # build qemu for x86_64 (default) diff --git a/libafl_sugar/Cargo.toml b/libafl_sugar/Cargo.toml index d0e2fde7a1..ba7a6f201b 100644 --- a/libafl_sugar/Cargo.toml +++ b/libafl_sugar/Cargo.toml @@ -12,6 +12,9 @@ edition = "2021" build = "build.rs" categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"] +[package.metadata.docs.rs] +all-features = true + [features] python = ["pyo3", "libafl_qemu/python", "pyo3-build-config"] default = [] diff --git a/libafl_targets/Cargo.toml b/libafl_targets/Cargo.toml index 1936d6f211..3767e23d65 100644 --- a/libafl_targets/Cargo.toml +++ b/libafl_targets/Cargo.toml @@ -12,6 +12,9 @@ edition = "2021" categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"] +[package.metadata.docs.rs] +all-features = true + [features] default = ["std", "sanitizers_flags"] std = ["libafl/std"] diff --git a/utils/gramatron/construct_automata/Cargo.toml b/utils/gramatron/construct_automata/Cargo.toml index 8056226fa8..2bc2f87666 100644 --- a/utils/gramatron/construct_automata/Cargo.toml +++ b/utils/gramatron/construct_automata/Cargo.toml @@ -15,10 +15,9 @@ categories = ["development-tools::testing", "emulators", "embedded", "os", "no-s # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +libafl = { path = "../../../libafl" } serde_json = "1.0" regex = "1" -postcard = "1.0" -lazy_static = "1.4.0" -libafl = { path = "../../../libafl" } +postcard = { version = "1.0", features = ["alloc"], default-features = false } # no_std compatible serde serialization format clap = { version = "4.0", features = ["derive"] } log = "0.4.20" diff --git a/utils/gramatron/construct_automata/src/main.rs b/utils/gramatron/construct_automata/src/main.rs index 7a74067845..0c94b337fa 100644 --- a/utils/gramatron/construct_automata/src/main.rs +++ b/utils/gramatron/construct_automata/src/main.rs @@ -4,14 +4,16 @@ use std::{ io::{BufReader, Write}, path::{Path, PathBuf}, rc::Rc, + sync::OnceLock, }; use clap::{self, Parser}; -use lazy_static::lazy_static; use libafl::generators::gramatron::{Automaton, Trigger}; use regex::Regex; use serde_json::Value; +static RE: OnceLock = OnceLock::new(); + #[derive(Debug, Parser)] #[command( name = "construct_automata", @@ -69,10 +71,8 @@ struct Stacks { } fn tokenize(rule: &str) -> (String, Vec, bool) { - lazy_static! { - static ref RE: Regex = Regex::new(r"([r])*'([\s\S]+)'([\s\S]*)").unwrap(); - } - let cap = RE.captures(rule).unwrap(); + let re = RE.get_or_init(|| Regex::new(r"([r])*'([\s\S]+)'([\s\S]*)").unwrap()); + let cap = re.captures(rule).unwrap(); let is_regex = cap.get(1).is_some(); let terminal = cap.get(2).unwrap().as_str().to_owned(); let ss = cap.get(3).map_or(vec![], |m| {