Fix baby_no_std (#846)
* Fixing baby_no_std * Fixed warnings for no_std * Fix aarch build, clippy * oops nyx again * Using CString from alloc
This commit is contained in:
parent
e8b3d33bf4
commit
28ab5e224b
@ -20,5 +20,4 @@ static-alloc = "0.2.3"
|
|||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
cstr_core = "0.2.3"
|
|
||||||
|
|
||||||
|
34
fuzzers/baby_no_std/Makefile.toml
Normal file
34
fuzzers/baby_no_std/Makefile.toml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
[env]
|
||||||
|
FUZZER_NAME="fuzzer"
|
||||||
|
PROJECT_DIR = { script = ["pwd"] }
|
||||||
|
|
||||||
|
[tasks.unsupported]
|
||||||
|
script_runner="@shell"
|
||||||
|
script='''
|
||||||
|
echo "Cargo-make not integrated yet on this"
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Fuzzer
|
||||||
|
[tasks.build]
|
||||||
|
command = "cargo"
|
||||||
|
args = ["build", "--release", "-Zbuild-std=core,alloc", "--target", "x86_64-unknown-linux-gnu"]
|
||||||
|
|
||||||
|
# Test
|
||||||
|
[tasks.test]
|
||||||
|
linux_alias = "test_unix"
|
||||||
|
mac_alias = "unsupported"
|
||||||
|
windows_alias = "unsupported"
|
||||||
|
|
||||||
|
[tasks.test_unix]
|
||||||
|
script='''
|
||||||
|
cargo run -Zbuild-std=core,alloc --target x86_64-unknown-linux-gnu || true
|
||||||
|
'''
|
||||||
|
dependencies = ["build"]
|
||||||
|
|
||||||
|
[tasks.build_aarch]
|
||||||
|
script = "cargo +nightly build -Zbuild-std=core,alloc --target aarch64-unknown-none -v --release"
|
||||||
|
|
||||||
|
# Clean
|
||||||
|
[tasks.clean]
|
||||||
|
command = "cargo"
|
||||||
|
args = ["clean"]
|
5
fuzzers/baby_no_std/build.rs
Normal file
5
fuzzers/baby_no_std/build.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
fn main() {
|
||||||
|
if std::env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default() == "unix" {
|
||||||
|
println!("cargo:rustc-link-lib=c");
|
||||||
|
};
|
||||||
|
}
|
1
fuzzers/baby_no_std/rust-toolchain
Normal file
1
fuzzers/baby_no_std/rust-toolchain
Normal file
@ -0,0 +1 @@
|
|||||||
|
nightly
|
@ -1,14 +1,16 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
// Embedded targets: build with no_main
|
// Embedded targets: build with no_main
|
||||||
#![cfg_attr(not(any(windows, unix)), no_main)]
|
#![cfg_attr(not(any(windows)), no_main)]
|
||||||
// Embedded needs alloc error handlers which only work on nightly right now...
|
// Embedded needs alloc error handlers which only work on nightly right now...
|
||||||
#![cfg_attr(not(any(windows, unix)), feature(default_alloc_error_handler))]
|
#![cfg_attr(not(any(windows)), feature(default_alloc_error_handler))]
|
||||||
|
|
||||||
#[cfg(not(any(windows, unix)))]
|
|
||||||
use core::panic::PanicInfo;
|
|
||||||
|
|
||||||
#[cfg(any(windows, unix))]
|
#[cfg(any(windows, unix))]
|
||||||
use cstr_core::CString;
|
extern crate alloc;
|
||||||
|
#[cfg(any(windows, unix))]
|
||||||
|
use alloc::ffi::CString;
|
||||||
|
#[cfg(not(any(windows)))]
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
use libafl::{
|
use libafl::{
|
||||||
bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice},
|
bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice},
|
||||||
corpus::InMemoryCorpus,
|
corpus::InMemoryCorpus,
|
||||||
@ -26,16 +28,22 @@ use libafl::{
|
|||||||
state::StdState,
|
state::StdState,
|
||||||
};
|
};
|
||||||
#[cfg(any(windows, unix))]
|
#[cfg(any(windows, unix))]
|
||||||
use libc::{c_char, printf};
|
use libc::{abort, printf};
|
||||||
use static_alloc::Bump;
|
use static_alloc::Bump;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static A: Bump<[u8; 512 * 1024 * 1024]> = Bump::uninit();
|
static A: Bump<[u8; 512 * 1024 * 1024]> = Bump::uninit();
|
||||||
|
|
||||||
#[cfg(not(any(windows, unix)))]
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(_info: &PanicInfo) -> ! {
|
fn panic(_info: &PanicInfo) -> ! {
|
||||||
loop {}
|
#[cfg(unix)]
|
||||||
|
unsafe {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
loop {
|
||||||
|
// On embedded, there's not much left to do.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Coverage map with explicit assignments due to the lack of instrumentation
|
/// Coverage map with explicit assignments due to the lack of instrumentation
|
||||||
@ -46,7 +54,7 @@ fn signals_set(idx: usize) {
|
|||||||
unsafe { SIGNALS[idx] = 1 };
|
unsafe { SIGNALS[idx] = 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Provide custom time in no_std environment
|
/// Provide custom time in `no_std` environment
|
||||||
/// Use a time provider of your choice
|
/// Use a time provider of your choice
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn external_current_millis() -> u64 {
|
pub extern "C" fn external_current_millis() -> u64 {
|
||||||
@ -54,8 +62,12 @@ pub extern "C" fn external_current_millis() -> u64 {
|
|||||||
1000
|
1000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The main of this program.
|
||||||
|
/// # Panics
|
||||||
|
/// Will panic once the fuzzer finds the correct conditions.
|
||||||
#[allow(clippy::similar_names)]
|
#[allow(clippy::similar_names)]
|
||||||
pub fn main() {
|
#[no_mangle]
|
||||||
|
pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
// The closure that we want to fuzz
|
// The closure that we want to fuzz
|
||||||
let mut harness = |input: &BytesInput| {
|
let mut harness = |input: &BytesInput| {
|
||||||
let target = input.target_bytes();
|
let target = input.target_bytes();
|
||||||
@ -65,6 +77,7 @@ pub fn main() {
|
|||||||
signals_set(1);
|
signals_set(1);
|
||||||
if buf.len() > 1 && buf[1] == b'b' {
|
if buf.len() > 1 && buf[1] == b'b' {
|
||||||
signals_set(2);
|
signals_set(2);
|
||||||
|
#[allow(clippy::manual_assert)]
|
||||||
if buf.len() > 2 && buf[2] == b'c' {
|
if buf.len() > 2 && buf[2] == b'c' {
|
||||||
panic!("=)");
|
panic!("=)");
|
||||||
}
|
}
|
||||||
@ -104,10 +117,8 @@ pub fn main() {
|
|||||||
// TODO: Print `s` here, if your target permits it.
|
// TODO: Print `s` here, if your target permits it.
|
||||||
#[cfg(any(windows, unix))]
|
#[cfg(any(windows, unix))]
|
||||||
unsafe {
|
unsafe {
|
||||||
printf(
|
let s = CString::new(s).unwrap();
|
||||||
b"%s\n\0".as_ptr() as *const c_char,
|
printf(b"%s\n\0".as_ptr().cast(), s.as_ptr());
|
||||||
CString::new(s).unwrap().as_ptr() as *const c_char,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -146,4 +157,6 @@ pub fn main() {
|
|||||||
fuzzer
|
fuzzer
|
||||||
.fuzz_loop(&mut stages, &mut executor, &mut state, &mut mgr)
|
.fuzz_loop(&mut stages, &mut executor, &mut state, &mut mgr)
|
||||||
.expect("Error in the fuzzing loop");
|
.expect("Error in the fuzzing loop");
|
||||||
|
|
||||||
|
0
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ categories = ["development-tools::testing", "emulators", "embedded", "os", "no-s
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std", "derive", "llmp_compression", "rand_trait", "fork", "prelude"]
|
default = ["std", "derive", "llmp_compression", "rand_trait", "fork", "prelude"]
|
||||||
std = ["serde_json", "serde_json/std", "hostname", "nix", "serde/std", "bincode", "wait-timeout", "regex", "byteorder", "once_cell", "uuid", "tui_monitor", "ctor", "backtrace"] # print, env, launcher ... support
|
std = ["serde_json", "serde_json/std", "hostname", "nix", "serde/std", "bincode", "wait-timeout", "regex", "byteorder", "once_cell", "uuid", "tui_monitor", "ctor", "backtrace", "uds"] # print, env, launcher ... support
|
||||||
derive = ["libafl_derive"] # provide derive(SerdeAny) macro.
|
derive = ["libafl_derive"] # provide derive(SerdeAny) macro.
|
||||||
fork = [] # uses the fork() syscall to spawn children, instead of launching a new command, if supported by the OS (has no effect on Windows, no_std).
|
fork = [] # uses the fork() syscall to spawn children, instead of launching a new command, if supported by the OS (has no effect on Windows, no_std).
|
||||||
rand_trait = ["rand_core"] # If set, libafl's rand implementations will implement `rand::Rng`
|
rand_trait = ["rand_core"] # If set, libafl's rand implementations will implement `rand::Rng`
|
||||||
@ -94,7 +94,7 @@ grammartec = { version = "0.2", optional = true }
|
|||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
libc = "0.2" # For (*nix) libc
|
libc = "0.2" # For (*nix) libc
|
||||||
uds = "0.2.6"
|
uds = { version = "0.2.6", optional = true }
|
||||||
lock_api = "0.4.7"
|
lock_api = "0.4.7"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
@ -452,7 +452,7 @@ impl InProcessExecutorHandlerData {
|
|||||||
self.in_target == 1
|
self.in_target == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(unix)]
|
||||||
fn is_valid(&self) -> bool {
|
fn is_valid(&self) -> bool {
|
||||||
!self.current_input_ptr.is_null()
|
!self.current_input_ptr.is_null()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user