Fix nix update (#2252) (#2255)

This commit is contained in:
Dominik Maier 2024-05-28 13:16:09 +02:00 committed by GitHub
parent 963afc3e5c
commit c3f67daefb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 51 additions and 71 deletions

View File

@ -488,7 +488,7 @@ impl Forkserver {
let st_read = unsafe { BorrowedFd::borrow_raw(st_read) }; let st_read = unsafe { BorrowedFd::borrow_raw(st_read) };
let mut readfds = FdSet::new(); 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) // 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( let sret = pselect(
Some(readfds.highest().unwrap().as_raw_fd() + 1), Some(readfds.highest().unwrap().as_raw_fd() + 1),

View File

@ -88,13 +88,6 @@ pub extern crate alloc;
#[allow(unused_imports)] #[allow(unused_imports)]
#[macro_use] #[macro_use]
extern crate libafl_derive; 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")] #[cfg(feature = "derive")]
#[doc(hidden)] #[doc(hidden)]
pub use libafl_derive::*; pub use libafl_derive::*;

View File

@ -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 // Linux Section
#[cfg(any( #[cfg(any(

View File

@ -199,17 +199,6 @@ use xxhash_rust::xxh3::xxh3_64;
)] )]
pub struct ClientId(pub u32); 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::{ use core::{
array::TryFromSliceError, array::TryFromSliceError,
fmt::{self, Display}, fmt::{self, Display},
@ -222,6 +211,8 @@ use std::{env::VarError, io};
#[cfg(feature = "libafl_derive")] #[cfg(feature = "libafl_derive")]
pub use libafl_derive::SerdeAny; pub use libafl_derive::SerdeAny;
#[cfg(feature = "std")]
use log::{Metadata, Record};
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use { use {
alloc::string::{FromUtf8Error, String}, alloc::string::{FromUtf8Error, String},

View File

@ -12,7 +12,7 @@ pub mod unix_signals;
#[cfg(unix)] #[cfg(unix)]
pub use unix_signals::CTRL_C_EXIT; pub use unix_signals::CTRL_C_EXIT;
#[cfg(all(unix, feature = "std"))] #[cfg(all(unix, feature = "alloc"))]
pub mod pipes; pub mod pipes;
#[cfg(all(unix, feature = "std"))] #[cfg(all(unix, feature = "std"))]

View File

@ -1,4 +1,7 @@
//! Unix `pipe` wrapper for `LibAFL` //! 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")] #[cfg(feature = "std")]
use std::{ use std::{
io::{self, ErrorKind, Read, Write}, io::{self, ErrorKind, Read, Write},
@ -6,7 +9,7 @@ use std::{
}; };
#[cfg(feature = "std")] #[cfg(feature = "std")]
use nix::unistd::{close, pipe, read, write}; use nix::unistd::{pipe, read, write};
use crate::Error; use crate::Error;
@ -15,9 +18,9 @@ use crate::Error;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Pipe { pub struct Pipe {
/// The read end of the pipe /// The read end of the pipe
read_end: Option<RawFd>, read_end: Option<Rc<RefCell<OwnedFd>>>,
/// The write end of the pipe /// The write end of the pipe
write_end: Option<RawFd>, write_end: Option<Rc<RefCell<OwnedFd>>>,
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -26,37 +29,39 @@ impl Pipe {
pub fn new() -> Result<Self, Error> { pub fn new() -> Result<Self, Error> {
let (read_end, write_end) = pipe()?; let (read_end, write_end) = pipe()?;
Ok(Self { Ok(Self {
read_end: Some(read_end), read_end: Some(Rc::new(RefCell::new(read_end))),
write_end: Some(write_end), write_end: Some(Rc::new(RefCell::new(write_end))),
}) })
} }
/// Close the read end of a pipe /// Close the read end of a pipe
pub fn close_read_end(&mut self) { pub fn close_read_end(&mut self) {
if let Some(read_end) = self.read_end { // `OwnedFd` closes on Drop
let _: Result<(), nix::errno::Errno> = close(read_end); self.read_end = None;
self.read_end = None;
}
} }
/// Close the write end of a pipe /// Close the write end of a pipe
pub fn close_write_end(&mut self) { pub fn close_write_end(&mut self) {
if let Some(write_end) = self.write_end { // `OwnedFd` closes on Drop
let _: Result<(), nix::errno::Errno> = close(write_end); self.write_end = None;
self.write_end = None;
}
} }
/// The read end /// The read end
#[must_use] #[must_use]
pub fn read_end(&self) -> Option<RawFd> { 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 /// The write end
#[must_use] #[must_use]
pub fn write_end(&self) -> Option<RawFd> { 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 { impl Read for Pipe {
/// Reads a few bytes /// Reads a few bytes
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> { 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) { Some(read_end) => match read(read_end, buf) {
Ok(res) => Ok(res), Ok(res) => Ok(res),
Err(e) => Err(io::Error::from_raw_os_error(e as i32)), Err(e) => Err(io::Error::from_raw_os_error(e as i32)),
@ -81,11 +86,14 @@ impl Read for Pipe {
impl Write for Pipe { impl Write for Pipe {
/// Writes a few bytes /// Writes a few bytes
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> { fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
match self.write_end { match self.write_end.as_ref() {
Some(write_end) => match write(write_end, buf) { Some(write_end) => {
Ok(res) => Ok(res), let borrowed: &RefCell<OwnedFd> = write_end;
Err(e) => Err(io::Error::from_raw_os_error(e as i32)), 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( None => Err(io::Error::new(
ErrorKind::BrokenPipe, ErrorKind::BrokenPipe,
"Write pipe end was already closed", "Write pipe end was already closed",
@ -97,15 +105,3 @@ impl Write for Pipe {
Ok(()) 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);
}
}
}

View File

@ -22,6 +22,7 @@ use std::{
env, env,
io::{Read, Write}, io::{Read, Write},
marker::PhantomData, marker::PhantomData,
os::fd::{AsFd, BorrowedFd},
rc::{Rc, Weak}, rc::{Rc, Weak},
sync::{Arc, Condvar, Mutex}, sync::{Arc, Condvar, Mutex},
thread::JoinHandle, thread::JoinHandle,
@ -36,6 +37,7 @@ use std::{
}; };
use hashbrown::HashMap; use hashbrown::HashMap;
use nix::poll::PollTimeout;
#[cfg(all(feature = "std", unix))] #[cfg(all(feature = "std", unix))]
use nix::poll::{poll, PollFd, PollFlags}; use nix::poll::{poll, PollFd, PollFlags};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -672,7 +674,7 @@ where
}; };
let mut poll_fds: Vec<PollFd> = vec![PollFd::new( let mut poll_fds: Vec<PollFd> = vec![PollFd::new(
&listener, listener.as_fd(),
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLRDBAND, PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLRDBAND,
)]; )];
@ -681,7 +683,7 @@ where
cvar.notify_one(); cvar.notify_one();
loop { loop {
match poll(&mut poll_fds, -1) { match poll(&mut poll_fds, PollTimeout::NONE) {
Ok(num_fds) if num_fds > 0 => (), Ok(num_fds) if num_fds > 0 => (),
Ok(_) => continue, Ok(_) => continue,
Err(e) => { Err(e) => {
@ -718,11 +720,10 @@ where
let pollfd = PollFd::new( let pollfd = PollFd::new(
// # Safety // # 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. // 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. // We did not develop this server with that new constraint in mind, but it is upheld by our code.
// The `new` function then gets the `raw_fd` from this stream, and operate on that int internally. unsafe { BorrowedFd::borrow_raw(stream.as_raw_fd()) },
unsafe { &*(&stream as *const _) },
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLRDBAND, PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLRDBAND,
); );

View File

@ -18,7 +18,7 @@ use std::ffi::CString;
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
pub use libc::c_ulong; pub use libc::c_ulong;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use nix::errno::{errno, Errno}; use nix::errno::Errno;
/// The special exit code when the target exited through ctrl-c /// The special exit code when the target exited through ctrl-c
pub const CTRL_C_EXIT: i32 = 100; pub const CTRL_C_EXIT: i32 = 100;
@ -518,7 +518,7 @@ pub fn ucontext() -> Result<ucontext_t, Error> {
#[cfg(feature = "std")] #[cfg(feature = "std")]
Err(Error::unknown(format!( Err(Error::unknown(format!(
"Failed to get ucontext: {:?}", "Failed to get ucontext: {:?}",
Errno::from_i32(errno()) Errno::last()
))) )))
} }
} else { } else {

View File

@ -522,6 +522,15 @@ pub struct Handle<T: ?Sized> {
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
impl<T: ?Sized> Handle<T> { 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. /// Fetch the name of the referenced instance.
/// ///
/// We explicitly do *not* implement [`Named`], as this could potentially lead to confusion /// We explicitly do *not* implement [`Named`], as this could potentially lead to confusion