parent
963afc3e5c
commit
c3f67daefb
@ -488,7 +488,7 @@ impl Forkserver {
|
||||
let st_read = unsafe { BorrowedFd::borrow_raw(st_read) };
|
||||
|
||||
let mut readfds = FdSet::new();
|
||||
readfds.insert(&st_read);
|
||||
readfds.insert(st_read);
|
||||
// We'll pass a copied timeout to keep the original timeout intact, because select updates timeout to indicate how much time was left. See select(2)
|
||||
let sret = pselect(
|
||||
Some(readfds.highest().unwrap().as_raw_fd() + 1),
|
||||
|
@ -88,13 +88,6 @@ pub extern crate alloc;
|
||||
#[allow(unused_imports)]
|
||||
#[macro_use]
|
||||
extern crate libafl_derive;
|
||||
/// Dummy export that will warn with a deprecation note on usage.
|
||||
/// Use the `libafl_bolts` crate instead.
|
||||
#[deprecated(
|
||||
since = "0.11.0",
|
||||
note = "All LibAFL bolts have moved to the libafl_bolts crate."
|
||||
)]
|
||||
pub mod bolts {}
|
||||
#[cfg(feature = "derive")]
|
||||
#[doc(hidden)]
|
||||
pub use libafl_derive::*;
|
||||
|
@ -203,16 +203,6 @@ impl TryFrom<&str> for Cores {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses core binding args from user input.
|
||||
/// Returns a Vec of CPU IDs.
|
||||
/// * `./fuzzer --cores 1,2-4,6`: clients run in cores 1,2,3,4,6
|
||||
/// * `./fuzzer --cores all`: one client runs on each available core
|
||||
#[cfg(feature = "std")]
|
||||
#[deprecated(since = "0.8.1", note = "Use Cores::from_cmdline instead")]
|
||||
pub fn parse_core_bind_arg(args: &str) -> Result<Vec<usize>, Error> {
|
||||
Ok(Cores::from_cmdline(args)?.ids.iter().map(|x| x.0).collect())
|
||||
}
|
||||
|
||||
// Linux Section
|
||||
|
||||
#[cfg(any(
|
||||
|
@ -199,17 +199,6 @@ use xxhash_rust::xxh3::xxh3_64;
|
||||
)]
|
||||
pub struct ClientId(pub u32);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use log::{Metadata, Record};
|
||||
|
||||
#[deprecated(
|
||||
since = "0.11.0",
|
||||
note = "The launcher module has moved out of `libafl_bolts` into `libafl::events::launcher`."
|
||||
)]
|
||||
/// Dummy module informing potential users that the launcher module has moved
|
||||
/// out of `libafl_bolts` into `libafl::events::launcher`.
|
||||
pub mod launcher {}
|
||||
|
||||
use core::{
|
||||
array::TryFromSliceError,
|
||||
fmt::{self, Display},
|
||||
@ -222,6 +211,8 @@ use std::{env::VarError, io};
|
||||
|
||||
#[cfg(feature = "libafl_derive")]
|
||||
pub use libafl_derive::SerdeAny;
|
||||
#[cfg(feature = "std")]
|
||||
use log::{Metadata, Record};
|
||||
#[cfg(feature = "alloc")]
|
||||
use {
|
||||
alloc::string::{FromUtf8Error, String},
|
||||
|
@ -12,7 +12,7 @@ pub mod unix_signals;
|
||||
#[cfg(unix)]
|
||||
pub use unix_signals::CTRL_C_EXIT;
|
||||
|
||||
#[cfg(all(unix, feature = "std"))]
|
||||
#[cfg(all(unix, feature = "alloc"))]
|
||||
pub mod pipes;
|
||||
|
||||
#[cfg(all(unix, feature = "std"))]
|
||||
|
@ -1,4 +1,7 @@
|
||||
//! Unix `pipe` wrapper for `LibAFL`
|
||||
use alloc::rc::Rc;
|
||||
use core::{borrow::Borrow, cell::RefCell};
|
||||
use std::os::fd::{AsFd, AsRawFd, OwnedFd};
|
||||
#[cfg(feature = "std")]
|
||||
use std::{
|
||||
io::{self, ErrorKind, Read, Write},
|
||||
@ -6,7 +9,7 @@ use std::{
|
||||
};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use nix::unistd::{close, pipe, read, write};
|
||||
use nix::unistd::{pipe, read, write};
|
||||
|
||||
use crate::Error;
|
||||
|
||||
@ -15,9 +18,9 @@ use crate::Error;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Pipe {
|
||||
/// The read end of the pipe
|
||||
read_end: Option<RawFd>,
|
||||
read_end: Option<Rc<RefCell<OwnedFd>>>,
|
||||
/// The write end of the pipe
|
||||
write_end: Option<RawFd>,
|
||||
write_end: Option<Rc<RefCell<OwnedFd>>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@ -26,37 +29,39 @@ impl Pipe {
|
||||
pub fn new() -> Result<Self, Error> {
|
||||
let (read_end, write_end) = pipe()?;
|
||||
Ok(Self {
|
||||
read_end: Some(read_end),
|
||||
write_end: Some(write_end),
|
||||
read_end: Some(Rc::new(RefCell::new(read_end))),
|
||||
write_end: Some(Rc::new(RefCell::new(write_end))),
|
||||
})
|
||||
}
|
||||
|
||||
/// Close the read end of a pipe
|
||||
pub fn close_read_end(&mut self) {
|
||||
if let Some(read_end) = self.read_end {
|
||||
let _: Result<(), nix::errno::Errno> = close(read_end);
|
||||
// `OwnedFd` closes on Drop
|
||||
self.read_end = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Close the write end of a pipe
|
||||
pub fn close_write_end(&mut self) {
|
||||
if let Some(write_end) = self.write_end {
|
||||
let _: Result<(), nix::errno::Errno> = close(write_end);
|
||||
// `OwnedFd` closes on Drop
|
||||
self.write_end = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// The read end
|
||||
#[must_use]
|
||||
pub fn read_end(&self) -> Option<RawFd> {
|
||||
self.read_end
|
||||
self.read_end.as_ref().map(|fd| {
|
||||
let borrowed: &RefCell<OwnedFd> = fd.borrow();
|
||||
borrowed.borrow().as_raw_fd()
|
||||
})
|
||||
}
|
||||
|
||||
/// The write end
|
||||
#[must_use]
|
||||
pub fn write_end(&self) -> Option<RawFd> {
|
||||
self.write_end
|
||||
self.write_end.as_ref().map(|fd| {
|
||||
let borrowed: &RefCell<OwnedFd> = fd.borrow();
|
||||
borrowed.borrow().as_raw_fd()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +69,7 @@ impl Pipe {
|
||||
impl Read for Pipe {
|
||||
/// Reads a few bytes
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
|
||||
match self.read_end {
|
||||
match self.read_end() {
|
||||
Some(read_end) => match read(read_end, buf) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(e) => Err(io::Error::from_raw_os_error(e as i32)),
|
||||
@ -81,11 +86,14 @@ impl Read for Pipe {
|
||||
impl Write for Pipe {
|
||||
/// Writes a few bytes
|
||||
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
|
||||
match self.write_end {
|
||||
Some(write_end) => match write(write_end, buf) {
|
||||
match self.write_end.as_ref() {
|
||||
Some(write_end) => {
|
||||
let borrowed: &RefCell<OwnedFd> = write_end;
|
||||
match write((*borrowed).borrow().as_fd(), buf) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(e) => Err(io::Error::from_raw_os_error(e as i32)),
|
||||
},
|
||||
}
|
||||
}
|
||||
None => Err(io::Error::new(
|
||||
ErrorKind::BrokenPipe,
|
||||
"Write pipe end was already closed",
|
||||
@ -97,15 +105,3 @@ impl Write for Pipe {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Drop for Pipe {
|
||||
fn drop(&mut self) {
|
||||
if let Some(read_end) = self.read_end {
|
||||
let _: Result<(), nix::errno::Errno> = close(read_end);
|
||||
}
|
||||
if let Some(write_end) = self.write_end {
|
||||
let _: Result<(), nix::errno::Errno> = close(write_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ use std::{
|
||||
env,
|
||||
io::{Read, Write},
|
||||
marker::PhantomData,
|
||||
os::fd::{AsFd, BorrowedFd},
|
||||
rc::{Rc, Weak},
|
||||
sync::{Arc, Condvar, Mutex},
|
||||
thread::JoinHandle,
|
||||
@ -36,6 +37,7 @@ use std::{
|
||||
};
|
||||
|
||||
use hashbrown::HashMap;
|
||||
use nix::poll::PollTimeout;
|
||||
#[cfg(all(feature = "std", unix))]
|
||||
use nix::poll::{poll, PollFd, PollFlags};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -672,7 +674,7 @@ where
|
||||
};
|
||||
|
||||
let mut poll_fds: Vec<PollFd> = vec![PollFd::new(
|
||||
&listener,
|
||||
listener.as_fd(),
|
||||
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLRDBAND,
|
||||
)];
|
||||
|
||||
@ -681,7 +683,7 @@ where
|
||||
cvar.notify_one();
|
||||
|
||||
loop {
|
||||
match poll(&mut poll_fds, -1) {
|
||||
match poll(&mut poll_fds, PollTimeout::NONE) {
|
||||
Ok(num_fds) if num_fds > 0 => (),
|
||||
Ok(_) => continue,
|
||||
Err(e) => {
|
||||
@ -718,11 +720,10 @@ where
|
||||
|
||||
let pollfd = PollFd::new(
|
||||
// # Safety
|
||||
// This cast will make `PollFd::new` ignore the lifetime of our stream.
|
||||
// Going through a raw fd will make `PollFd::new` ignore the lifetime of our stream.
|
||||
// As of nix 0.27, the `PollFd` is safer, in that it checks the lifetime of the given stream.
|
||||
// We did not develop this server with that new constraint in mind, but it is upheld.
|
||||
// The `new` function then gets the `raw_fd` from this stream, and operate on that int internally.
|
||||
unsafe { &*(&stream as *const _) },
|
||||
// We did not develop this server with that new constraint in mind, but it is upheld by our code.
|
||||
unsafe { BorrowedFd::borrow_raw(stream.as_raw_fd()) },
|
||||
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLRDBAND,
|
||||
);
|
||||
|
||||
|
@ -18,7 +18,7 @@ use std::ffi::CString;
|
||||
#[cfg(target_arch = "arm")]
|
||||
pub use libc::c_ulong;
|
||||
#[cfg(feature = "std")]
|
||||
use nix::errno::{errno, Errno};
|
||||
use nix::errno::Errno;
|
||||
|
||||
/// The special exit code when the target exited through ctrl-c
|
||||
pub const CTRL_C_EXIT: i32 = 100;
|
||||
@ -518,7 +518,7 @@ pub fn ucontext() -> Result<ucontext_t, Error> {
|
||||
#[cfg(feature = "std")]
|
||||
Err(Error::unknown(format!(
|
||||
"Failed to get ucontext: {:?}",
|
||||
Errno::from_i32(errno())
|
||||
Errno::last()
|
||||
)))
|
||||
}
|
||||
} else {
|
||||
|
@ -522,6 +522,15 @@ pub struct Handle<T: ?Sized> {
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<T: ?Sized> Handle<T> {
|
||||
/// Create a new [`Handle`] with the given name.
|
||||
#[must_use]
|
||||
pub fn new(name: Cow<'static, str>) -> Self {
|
||||
Self {
|
||||
name,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch the name of the referenced instance.
|
||||
///
|
||||
/// We explicitly do *not* implement [`Named`], as this could potentially lead to confusion
|
||||
|
Loading…
x
Reference in New Issue
Block a user