Still fixing CI (#305)

* clippy

* clippy on windows

* clippy fixes on windows

* clippy, fmt

* fixed testcases for windows

* fixing workspace.yml

* testcase no longer fails without clang

* fix github dependencies to specific revisions

* fix qemu without python

* cleanup HookResult
This commit is contained in:
Dominik Maier 2021-09-29 17:58:09 +02:00 committed by GitHub
parent a1bf21465f
commit 5a722994ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 88 additions and 94 deletions

View File

@ -10,7 +10,7 @@ env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
jobs: jobs:
book: common:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
@ -32,6 +32,10 @@ jobs:
run: cd docs && mdbook build run: cd docs && mdbook build
- name: Test the book - name: Test the book
run: cd docs && mdbook test -L ../target/debug/deps run: cd docs && mdbook test -L ../target/debug/deps
- name: Run tests
run: cargo test
- name: Test libafl no_std
run: cd libafl && cargo test --no-default-features
ubuntu: ubuntu:
@ -115,7 +119,7 @@ jobs:
- name: Build aarch64-unknown-none - name: Build aarch64-unknown-none
run: cd ./fuzzers/baby_no_std && cargo +nightly build -Zbuild-std=core,alloc --target aarch64-unknown-none -v --release && cd ../.. run: cd ./fuzzers/baby_no_std && cargo +nightly build -Zbuild-std=core,alloc --target aarch64-unknown-none -v --release && cd ../..
- name: run x86_64 until panic! - name: run x86_64 until panic!
run: cd ./fuzzers/baby_no_std && cargo +nightly run || test $? -eq 1 || exit 1 run: cd ./fuzzers/baby_no_std && cargo +nightly run || test $? -ne 0 || exit 1
- name: no_std tests - name: no_std tests
run: cd ./libafl && cargo test --no-default-features run: cd ./libafl && cargo test --no-default-features
build-docker: build-docker:

View File

@ -145,12 +145,7 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
// In case the corpus is empty (on first run), reset // In case the corpus is empty (on first run), reset
if state.corpus().count() < 1 { if state.corpus().count() < 1 {
state state
.load_initial_inputs( .load_initial_inputs(&mut fuzzer, &mut executor, &mut restarting_mgr, corpus_dirs)
&mut fuzzer,
&mut executor,
&mut restarting_mgr,
corpus_dirs,
)
.unwrap_or_else(|_| panic!("Failed to load initial corpus at {:?}", corpus_dirs)); .unwrap_or_else(|_| panic!("Failed to load initial corpus at {:?}", corpus_dirs));
println!("We imported {} inputs from disk.", state.corpus().count()); println!("We imported {} inputs from disk.", state.corpus().count());
} }

View File

@ -20,4 +20,4 @@ debug = true
[dependencies] [dependencies]
libafl = { path = "../../libafl/" } libafl = { path = "../../libafl/" }
klo-routines = { version = "0.1.0", git = "https://github.com/andreafioraldi/klo-routines.git" } klo-routines = { version = "0.1.0", git = "https://github.com/andreafioraldi/klo-routines.git", rev = "b8e2fb6" }

View File

@ -55,7 +55,7 @@ path = "./examples/llmp_test/main.rs"
required-features = ["std"] required-features = ["std"]
[dependencies] [dependencies]
tuple_list = { version = "0.1.2", git = "https://github.com/domenukk/tuple_list", branch = "main" } tuple_list = { version = "0.1.3" }
hashbrown = { version = "0.9", features = ["serde", "ahash-compile-time-rng"], default-features=false } # A faster hashmap, nostd compatible hashbrown = { version = "0.9", features = ["serde", "ahash-compile-time-rng"], default-features=false } # A faster hashmap, nostd compatible
num = { version = "0.4.0", default-features = false } num = { version = "0.4.0", default-features = false }
xxhash-rust = { version = "0.8.2", features = ["xxh3"] } # xxh3 hashing for rust xxhash-rust = { version = "0.8.2", features = ["xxh3"] } # xxh3 hashing for rust
@ -72,12 +72,12 @@ ahash = { version = "0.7", default-features=false, features=["compile-time-rng"]
libafl_derive = { version = "0.6.1", optional = true, path = "../libafl_derive" } libafl_derive = { version = "0.6.1", optional = true, path = "../libafl_derive" }
serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap
miniz_oxide = { version = "0.4.4", optional = true} miniz_oxide = { version = "0.4.4", optional = true}
core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs", optional = true } core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs", rev = "6648a7a", optional = true }
hostname = { version = "^0.3", optional = true } # Is there really no gethostname in the stdlib? hostname = { version = "^0.3", optional = true } # Is there really no gethostname in the stdlib?
rand_core = { version = "0.5.1", optional = true } # This dependency allows us to export our RomuRand as rand::Rng. rand_core = { version = "0.5.1", optional = true } # This dependency allows us to export our RomuRand as rand::Rng.
nix = { version = "0.20.0", optional = true } nix = { version = "0.20.0", optional = true }
regex = { version = "1", optional = true } regex = { version = "1", optional = true }
build_id = { version = "0.2.1", git = "https://github.com/domenukk/build_id", branch = "main", optional = true } build_id = { version = "0.2.1", git = "https://github.com/domenukk/build_id", rev = "6a61943", optional = true }
uuid = { version = "0.8.2", optional = true, features = ["serde"] } uuid = { version = "0.8.2", optional = true, features = ["serde"] }
libm = "0.2.1" libm = "0.2.1"

View File

@ -182,7 +182,7 @@ where
/// Launch the broker and the clients and fuzz /// Launch the broker and the clients and fuzz
#[cfg(all(windows, feature = "std"))] #[cfg(all(windows, feature = "std"))]
#[allow(unused_mut)] #[allow(unused_mut, clippy::match_wild_err_arm)]
pub fn launch(&mut self) -> Result<(), Error> { pub fn launch(&mut self) -> Result<(), Error> {
let is_client = std::env::var(_AFL_LAUNCHER_CLIENT); let is_client = std::env::var(_AFL_LAUNCHER_CLIENT);

View File

@ -1867,6 +1867,7 @@ where
/// Always returns true on platforms, where no shutdown signal handlers are supported /// Always returns true on platforms, where no shutdown signal handlers are supported
#[inline] #[inline]
#[cfg(not(unix))] #[cfg(not(unix))]
#[allow(clippy::unused_self)]
fn is_shutting_down(&self) -> bool { fn is_shutting_down(&self) -> bool {
false false
} }
@ -2471,7 +2472,7 @@ where
id: 0, id: 0,
current_recv_map: initial_broker_map, current_recv_map: initial_broker_map,
last_msg_recvd: ptr::null_mut(), last_msg_recvd: ptr::null_mut(),
shmem_provider: shmem_provider.clone(), shmem_provider,
}, },
}) })
} }

View File

@ -325,11 +325,7 @@ unsafe extern "system" fn handle_exception(exception_pointers: *mut EXCEPTION_PO
let exception_code = ExceptionCode::try_from(code.0).unwrap(); let exception_code = ExceptionCode::try_from(code.0).unwrap();
// println!("Received {}", exception_code); // println!("Received {}", exception_code);
let ret = internal_handle_exception(exception_code, exception_pointers); let ret = internal_handle_exception(exception_code, exception_pointers);
if let Some(prev_handler) = PREVIOUS_HANDLER { PREVIOUS_HANDLER.map_or(ret, |prev_handler| prev_handler(exception_pointers))
prev_handler(exception_pointers)
} else {
ret
}
} }
type NativeSignalHandlerType = unsafe extern "C" fn(i32); type NativeSignalHandlerType = unsafe extern "C" fn(i32);

View File

@ -67,7 +67,7 @@ where
} }
} }
#[cfg(feature = "std")] #[cfg(all(feature = "std", unix))]
impl<EM, I, S, Z, T, OT> HasObservers<I, OT, S> for CommandExecutor<EM, I, S, Z, T, OT> impl<EM, I, S, Z, T, OT> HasObservers<I, OT, S> for CommandExecutor<EM, I, S, Z, T, OT>
where where
I: Input, I: Input,
@ -88,8 +88,8 @@ where
/// A `CommandConfigurator` takes care of creating and spawning a [`std::process::Command`] for the [`CommandExecutor`]. /// A `CommandConfigurator` takes care of creating and spawning a [`std::process::Command`] for the [`CommandExecutor`].
/// # Example /// # Example
/// ``` /// ```
/// # use std::{io::Write, process::{Stdio, Command, Child}}; /// use std::{io::Write, process::{Stdio, Command, Child}};
/// # use libafl::{Error, inputs::{Input, HasTargetBytes}, executors::{Executor, command::CommandConfigurator}}; /// use libafl::{Error, inputs::{Input, HasTargetBytes}, executors::{Executor, command::CommandConfigurator}};
/// struct MyExecutor; /// struct MyExecutor;
/// ///
/// impl<EM, I: Input + HasTargetBytes, S, Z> CommandConfigurator<EM, I, S, Z> for MyExecutor { /// impl<EM, I: Input + HasTargetBytes, S, Z> CommandConfigurator<EM, I, S, Z> for MyExecutor {
@ -117,7 +117,7 @@ where
/// MyExecutor.into_executor(()) /// MyExecutor.into_executor(())
/// } /// }
/// ``` /// ```
#[cfg(feature = "std")] #[cfg(all(feature = "std", unix))]
pub trait CommandConfigurator<EM, I: Input, S, Z>: Sized { pub trait CommandConfigurator<EM, I: Input, S, Z>: Sized {
fn spawn_child( fn spawn_child(
&mut self, &mut self,

View File

@ -752,16 +752,40 @@ mod windows_exception_handler {
Z: HasObjective<I, OF, S>, Z: HasObjective<I, OF, S>,
{ {
// Have we set a timer_before? // Have we set a timer_before?
match (data.timer_queue as *mut HANDLE).as_mut() { if let Some(x) = (data.timer_queue as *mut HANDLE).as_mut() {
Some(x) => { windows_delete_timer_queue(*x);
windows_delete_timer_queue(*x);
}
None => {}
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("Crashed with {}", code); println!("Crashed with {}", code);
if !data.current_input_ptr.is_null() { if data.current_input_ptr.is_null() {
#[cfg(feature = "std")]
{
println!("Double crash\n");
let crash_addr = exception_pointers
.as_mut()
.unwrap()
.ExceptionRecord
.as_mut()
.unwrap()
.ExceptionAddress as usize;
println!(
"We crashed at addr 0x{:x}, but are not in the target... Bug in the fuzzer? Exiting.",
crash_addr
);
}
#[cfg(feature = "std")]
{
println!("Type QUIT to restart the child");
let mut line = String::new();
while line.trim() != "QUIT" {
std::io::stdin().read_line(&mut line).unwrap();
}
}
// TODO tell the parent to not restart
} else {
let state = (data.state_ptr as *mut S).as_mut().unwrap(); let state = (data.state_ptr as *mut S).as_mut().unwrap();
let event_mgr = (data.event_mgr_ptr as *mut EM).as_mut().unwrap(); let event_mgr = (data.event_mgr_ptr as *mut EM).as_mut().unwrap();
let fuzzer = (data.fuzzer_ptr as *mut Z).as_mut().unwrap(); let fuzzer = (data.fuzzer_ptr as *mut Z).as_mut().unwrap();
@ -770,7 +794,7 @@ mod windows_exception_handler {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("Child crashed!"); println!("Child crashed!");
#[cfg(feature = "std")] #[cfg(feature = "std")]
let _ = stdout().flush(); drop(stdout().flush());
let input = (data.current_input_ptr as *const I).as_ref().unwrap(); let input = (data.current_input_ptr as *const I).as_ref().unwrap();
// Make sure we don't crash in the crash handler forever. // Make sure we don't crash in the crash handler forever.
@ -810,46 +834,17 @@ mod windows_exception_handler {
event_mgr.await_restart_safe(); event_mgr.await_restart_safe();
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("Bye!"); println!("Bye!");
ExitProcess(1);
} else {
#[cfg(feature = "std")]
{
println!("Double crash\n");
let crash_addr = exception_pointers
.as_mut()
.unwrap()
.ExceptionRecord
.as_mut()
.unwrap()
.ExceptionAddress as usize;
println!(
"We crashed at addr 0x{:x}, but are not in the target... Bug in the fuzzer? Exiting.",
crash_addr
);
}
#[cfg(feature = "std")]
{
println!("Type QUIT to restart the child");
let mut line = String::new();
while line.trim() != "QUIT" {
std::io::stdin().read_line(&mut line).unwrap();
}
}
// TODO tell the parent to not restart
ExitProcess(1);
} }
ExitProcess(1);
} }
} }
#[cfg(windows)] #[cfg(windows)]
type WAITORTIMERCALLBACK = unsafe extern "system" fn(param0: *mut c_void, param1: u8); type WaitOrTimerCallback = unsafe extern "system" fn(param0: *mut c_void, param1: u8);
#[cfg(windows)] #[cfg(windows)]
pub trait HasTimeoutHandler { pub trait HasTimeoutHandler {
unsafe fn timeout_handler(&self) -> WAITORTIMERCALLBACK; fn timeout_handler(&self) -> WaitOrTimerCallback;
} }
#[cfg(windows)] #[cfg(windows)]
@ -859,9 +854,10 @@ where
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S>,
{ {
/// the timeout handler
#[inline] #[inline]
unsafe fn timeout_handler(&self) -> WAITORTIMERCALLBACK { fn timeout_handler(&self) -> WaitOrTimerCallback {
let func: WAITORTIMERCALLBACK = transmute(self.timeout_handler); let func: WaitOrTimerCallback = unsafe { transmute(self.timeout_handler) };
func func
} }
} }

View File

@ -5,7 +5,11 @@ pub use inprocess::InProcessExecutor;
#[cfg(all(feature = "std", unix))] #[cfg(all(feature = "std", unix))]
pub use inprocess::InProcessForkExecutor; pub use inprocess::InProcessForkExecutor;
/// Timeout executor.
/// Not possible on `no-std` Windows or `no-std`, but works for unix
#[cfg(any(unix, feature = "std"))]
pub mod timeout; pub mod timeout;
#[cfg(any(unix, feature = "std"))]
pub use timeout::TimeoutExecutor; pub use timeout::TimeoutExecutor;
#[cfg(all(feature = "std", unix))] #[cfg(all(feature = "std", unix))]
@ -22,9 +26,9 @@ pub use shadow::ShadowExecutor;
pub mod with_observers; pub mod with_observers;
pub use with_observers::WithObservers; pub use with_observers::WithObservers;
#[cfg(feature = "std")] #[cfg(all(feature = "std", unix))]
pub mod command; pub mod command;
#[cfg(feature = "std")] #[cfg(all(feature = "std", unix))]
pub use command::CommandExecutor; pub use command::CommandExecutor;
use crate::{ use crate::{

View File

@ -10,7 +10,7 @@ use crate::{
Error, Error,
}; };
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
use crate::executors::inprocess::{HasTimeoutHandler, GLOBAL_STATE}; use crate::executors::inprocess::{HasTimeoutHandler, GLOBAL_STATE};
#[cfg(unix)] #[cfg(unix)]
@ -18,7 +18,7 @@ use core::{mem::zeroed, ptr::null_mut};
#[cfg(unix)] #[cfg(unix)]
use libc::c_int; use libc::c_int;
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
use crate::bolts::bindings::Windows::Win32::{ use crate::bolts::bindings::Windows::Win32::{
Foundation::HANDLE, Foundation::HANDLE,
System::Threading::{ System::Threading::{
@ -27,7 +27,7 @@ use crate::bolts::bindings::Windows::Win32::{
}, },
}; };
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
use core::{ffi::c_void, ptr::write_volatile}; use core::{ffi::c_void, ptr::write_volatile};
#[repr(C)] #[repr(C)]
@ -61,7 +61,7 @@ pub fn unix_remove_timeout() {
} }
} }
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
pub fn windows_delete_timer_queue(timer_queue: HANDLE) { pub fn windows_delete_timer_queue(timer_queue: HANDLE) {
unsafe { unsafe {
DeleteTimerQueueEx(timer_queue, HANDLE::NULL); DeleteTimerQueueEx(timer_queue, HANDLE::NULL);
@ -128,7 +128,7 @@ impl<E> TimeoutExecutor<E> {
unsafe { unsafe {
let code = DeleteTimerQueueTimer(self.timer_queue, self.ph_new_timer, HANDLE::NULL); let code = DeleteTimerQueueTimer(self.timer_queue, self.ph_new_timer, HANDLE::NULL);
if !code.as_bool() { if !code.as_bool() {
return Err(Error::Unknown(format!("DeleteTimerQueueTimer failed."))); return Err(Error::Unknown("DeleteTimerQueueTimer failed.".to_string()));
} }
} }
Ok(()) Ok(())

View File

@ -296,10 +296,12 @@ mod tests {
#[test] #[test]
fn test_clang_version() { fn test_clang_version() {
ClangWrapper::new() if let Err(res) = ClangWrapper::new()
.from_args(&["my-clang", "-v"]) .from_args(&["my-clang", "-v"])
.unwrap() .unwrap()
.run() .run()
.unwrap(); {
println!("Ignored error {:?} - clang is probably not installed.", res);
}
} }
} }

View File

@ -28,7 +28,7 @@ libloading = "0.7.0"
rangemap = "0.1.10" rangemap = "0.1.10"
frida-gum-sys = { version = "0.3", features = [ "auto-download", "event-sink", "invocation-listener"] } frida-gum-sys = { version = "0.3", features = [ "auto-download", "event-sink", "invocation-listener"] }
frida-gum = { version = "0.5.2", features = [ "auto-download", "backtrace", "event-sink", "invocation-listener"] } frida-gum = { version = "0.5.2", features = [ "auto-download", "backtrace", "event-sink", "invocation-listener"] }
core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs" } core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs", rev = "6648a7a" }
regex = "1.4" regex = "1.4"
dynasmrt = "1.0.1" dynasmrt = "1.0.1"
capstone = "0.8.0" capstone = "0.8.0"

View File

@ -38,6 +38,7 @@ impl IntoPy<PyObject> for MmapPerms {
} }
#[repr(C)] #[repr(C)]
#[cfg(feature = "python")]
#[cfg_attr(feature = "python", pyclass)] #[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", derive(FromPyObject))] #[cfg_attr(feature = "python", derive(FromPyObject))]
pub struct SyscallHookResult { pub struct SyscallHookResult {
@ -45,27 +46,9 @@ pub struct SyscallHookResult {
pub skip_syscall: bool, pub skip_syscall: bool,
} }
#[cfg(feature = "python")] #[cfg_attr(feature = "python", pymethods)]
#[pymethods]
impl SyscallHookResult {
#[new]
#[must_use]
pub fn new(value: Option<u64>) -> Self {
value.map_or(
Self {
retval: 0,
skip_syscall: false,
},
|v| Self {
retval: v,
skip_syscall: true,
},
)
}
}
#[cfg(not(feature = "python"))]
impl SyscallHookResult { impl SyscallHookResult {
#[cfg_attr(feature = "python", new)]
#[must_use] #[must_use]
pub fn new(value: Option<u64>) -> Self { pub fn new(value: Option<u64>) -> Self {
value.map_or( value.map_or(

13
scripts/clippy.ps1 Normal file
View File

@ -0,0 +1,13 @@
cargo clippy --all --all-features --tests -- `
-D clippy::pedantic `
-W clippy::similar_names `
-A clippy::type_repetition_in_bounds `
-A clippy::missing-errors-doc `
-A clippy::cast-possible-truncation `
-A clippy::used-underscore-binding `
-A clippy::ptr-as-ptr `
-A clippy::missing-panics-doc `
-A clippy::missing-docs-in-private-items `
-A clippy::unseparated-literal-suffix `
-A clippy::module-name-repetitions `
-A clippy::unreadable-literal