mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-17 20:28:08 +00:00
use OsStr instead of CStr for file paths
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
#![cfg(os_family = "unix")]
|
||||||
//! Somewhat safe and somewhat ergonomic bindings for creating [AFL++](https://github.com/AFLplusplus/AFLplusplus) [custom mutators](https://github.com/AFLplusplus/AFLplusplus/blob/stable/docs/custom_mutators.md) in Rust.
|
//! Somewhat safe and somewhat ergonomic bindings for creating [AFL++](https://github.com/AFLplusplus/AFLplusplus) [custom mutators](https://github.com/AFLplusplus/AFLplusplus/blob/stable/docs/custom_mutators.md) in Rust.
|
||||||
//!
|
//!
|
||||||
//! # Usage
|
//! # Usage
|
||||||
@ -23,7 +24,7 @@
|
|||||||
//! The state is passed to [`CustomMutator::init`], when the feature is activated.
|
//! The state is passed to [`CustomMutator::init`], when the feature is activated.
|
||||||
//!
|
//!
|
||||||
//! _This is completely unsafe and uses automatically generated types extracted from the AFL++ source._
|
//! _This is completely unsafe and uses automatically generated types extracted from the AFL++ source._
|
||||||
use std::{ffi::CStr, fmt::Debug};
|
use std::{ffi::OsStr, fmt::Debug};
|
||||||
|
|
||||||
#[cfg(feature = "afl_internals")]
|
#[cfg(feature = "afl_internals")]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
@ -52,9 +53,14 @@ pub trait RawCustomMutator {
|
|||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queue_new_entry(&mut self, filename_new_queue: &CStr, _filename_orig_queue: Option<&CStr>) {}
|
fn queue_new_entry(
|
||||||
|
&mut self,
|
||||||
|
filename_new_queue: &OsStr,
|
||||||
|
_filename_orig_queue: Option<&OsStr>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
fn queue_get(&mut self, filename: &CStr) -> bool {
|
fn queue_get(&mut self, filename: &OsStr) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,16 +87,16 @@ pub mod wrappers {
|
|||||||
#[cfg(feature = "afl_internals")]
|
#[cfg(feature = "afl_internals")]
|
||||||
use custom_mutator_sys::afl_state;
|
use custom_mutator_sys::afl_state;
|
||||||
|
|
||||||
use core::slice;
|
|
||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
ffi::{c_void, CStr},
|
ffi::{c_void, CStr, OsStr},
|
||||||
mem::ManuallyDrop,
|
mem::ManuallyDrop,
|
||||||
os::raw::c_char,
|
os::{raw::c_char, unix::ffi::OsStrExt},
|
||||||
panic::catch_unwind,
|
panic::catch_unwind,
|
||||||
process::abort,
|
process::abort,
|
||||||
ptr::null,
|
ptr::null,
|
||||||
|
slice,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::RawCustomMutator;
|
use crate::RawCustomMutator;
|
||||||
@ -248,9 +254,12 @@ pub mod wrappers {
|
|||||||
if filename_new_queue.is_null() {
|
if filename_new_queue.is_null() {
|
||||||
panic!("received null filename_new_queue in afl_custom_queue_new_entry");
|
panic!("received null filename_new_queue in afl_custom_queue_new_entry");
|
||||||
}
|
}
|
||||||
let filename_new_queue = unsafe { CStr::from_ptr(filename_new_queue) };
|
let filename_new_queue =
|
||||||
|
OsStr::from_bytes(unsafe { CStr::from_ptr(filename_new_queue) }.to_bytes());
|
||||||
let filename_orig_queue = if !filename_orig_queue.is_null() {
|
let filename_orig_queue = if !filename_orig_queue.is_null() {
|
||||||
Some(unsafe { CStr::from_ptr(filename_orig_queue) })
|
Some(OsStr::from_bytes(
|
||||||
|
unsafe { CStr::from_ptr(filename_orig_queue) }.to_bytes(),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -326,9 +335,9 @@ pub mod wrappers {
|
|||||||
let mut context = FFIContext::<M>::from(data);
|
let mut context = FFIContext::<M>::from(data);
|
||||||
assert!(!filename.is_null());
|
assert!(!filename.is_null());
|
||||||
|
|
||||||
context
|
context.mutator.queue_get(OsStr::from_bytes(
|
||||||
.mutator
|
unsafe { CStr::from_ptr(filename) }.to_bytes(),
|
||||||
.queue_get(unsafe { CStr::from_ptr(filename) }) as u8
|
)) as u8
|
||||||
}) {
|
}) {
|
||||||
Ok(ret) => ret,
|
Ok(ret) => ret,
|
||||||
Err(err) => panic_handler("afl_custom_queue_get", err),
|
Err(err) => panic_handler("afl_custom_queue_get", err),
|
||||||
@ -532,13 +541,13 @@ pub trait CustomMutator {
|
|||||||
|
|
||||||
fn queue_new_entry(
|
fn queue_new_entry(
|
||||||
&mut self,
|
&mut self,
|
||||||
filename_new_queue: &CStr,
|
filename_new_queue: &OsStr,
|
||||||
filename_orig_queue: Option<&CStr>,
|
filename_orig_queue: Option<&OsStr>,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queue_get(&mut self, filename: &CStr) -> Result<bool, Self::Error> {
|
fn queue_get(&mut self, filename: &OsStr) -> Result<bool, Self::Error> {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,7 +618,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queue_new_entry(&mut self, filename_new_queue: &CStr, filename_orig_queue: Option<&CStr>) {
|
fn queue_new_entry(&mut self, filename_new_queue: &OsStr, filename_orig_queue: Option<&OsStr>) {
|
||||||
match self.queue_new_entry(filename_new_queue, filename_orig_queue) {
|
match self.queue_new_entry(filename_new_queue, filename_orig_queue) {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -618,7 +627,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queue_get(&mut self, filename: &CStr) -> bool {
|
fn queue_get(&mut self, filename: &OsStr) -> bool {
|
||||||
match self.queue_get(filename) {
|
match self.queue_get(filename) {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#![cfg(os_family="unix")]
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
use custom_mutator::{export_mutator, CustomMutator};
|
use custom_mutator::{export_mutator, CustomMutator};
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![cfg(os_family="unix")]
|
||||||
|
|
||||||
use custom_mutator::{export_mutator, CustomMutator};
|
use custom_mutator::{export_mutator, CustomMutator};
|
||||||
use lain::{
|
use lain::{
|
||||||
mutator::Mutator,
|
mutator::Mutator,
|
||||||
|
Reference in New Issue
Block a user