bolts: fix static mutable use (#1793)

This commit is contained in:
David CARLIER 2024-01-16 13:32:42 +00:00 committed by GitHub
parent c240cdec38
commit 61718c4e88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -168,6 +168,8 @@ use alloc::vec::Vec;
use core::hash::BuildHasher; use core::hash::BuildHasher;
#[cfg(any(feature = "xxh3", feature = "alloc"))] #[cfg(any(feature = "xxh3", feature = "alloc"))]
use core::hash::Hasher; use core::hash::Hasher;
#[cfg(all(unix, feature = "std"))]
use core::ptr;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(all(unix, feature = "std"))] #[cfg(all(unix, feature = "std"))]
@ -940,7 +942,7 @@ impl SimpleFdLogger {
// We also access a shared variable here. // We also access a shared variable here.
unsafe { unsafe {
LIBAFL_RAWFD_LOGGER.set_fd(log_fd); LIBAFL_RAWFD_LOGGER.set_fd(log_fd);
log::set_logger(&LIBAFL_RAWFD_LOGGER)?; log::set_logger(&*ptr::addr_of!(LIBAFL_RAWFD_LOGGER))?;
} }
Ok(()) Ok(())
} }
@ -1150,6 +1152,9 @@ pub mod pybind {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[cfg(all(feature = "std", unix))]
use core::ptr;
#[cfg(all(feature = "std", unix))] #[cfg(all(feature = "std", unix))]
use crate::LIBAFL_RAWFD_LOGGER; use crate::LIBAFL_RAWFD_LOGGER;
@ -1160,7 +1165,7 @@ mod tests {
unsafe { LIBAFL_RAWFD_LOGGER.fd = stdout().as_raw_fd() }; unsafe { LIBAFL_RAWFD_LOGGER.fd = stdout().as_raw_fd() };
unsafe { unsafe {
log::set_logger(&LIBAFL_RAWFD_LOGGER).unwrap(); log::set_logger(&*ptr::addr_of!(LIBAFL_RAWFD_LOGGER)).unwrap();
} }
log::set_max_level(log::LevelFilter::Debug); log::set_max_level(log::LevelFilter::Debug);
log::info!("Test"); log::info!("Test");

View File

@ -2267,7 +2267,9 @@ where
#[cfg(any(all(unix, not(miri)), all(windows, feature = "std")))] #[cfg(any(all(unix, not(miri)), all(windows, feature = "std")))]
fn setup_handlers() { fn setup_handlers() {
#[cfg(all(unix, not(miri)))] #[cfg(all(unix, not(miri)))]
if let Err(e) = unsafe { setup_signal_handler(&mut LLMP_SIGHANDLER_STATE) } { if let Err(e) =
unsafe { setup_signal_handler(&mut *ptr::addr_of_mut!(LLMP_SIGHANDLER_STATE)) }
{
// We can live without a proper ctrl+c signal handler - Ignore. // We can live without a proper ctrl+c signal handler - Ignore.
log::info!("Failed to setup signal handlers: {e}"); log::info!("Failed to setup signal handlers: {e}");
} else { } else {
@ -2275,7 +2277,7 @@ where
} }
#[cfg(all(windows, feature = "std"))] #[cfg(all(windows, feature = "std"))]
if let Err(e) = unsafe { setup_ctrl_handler(&mut LLMP_SIGHANDLER_STATE) } { if let Err(e) = unsafe { setup_ctrl_handler(ptr::addr_of_mut!(LLMP_SIGHANDLER_STATE)) } {
// We can live without a proper ctrl+c signal handler - Ignore. // We can live without a proper ctrl+c signal handler - Ignore.
log::info!("Failed to setup control handlers: {e}"); log::info!("Failed to setup control handlers: {e}");
} else { } else {

View File

@ -436,7 +436,7 @@ static mut CTRL_HANDLER: Option<CtrlHandlerHolder> = None;
/// # Safety /// # Safety
/// Same safety considerations as in `setup_exception_handler` /// Same safety considerations as in `setup_exception_handler`
pub(crate) unsafe fn setup_ctrl_handler<T: 'static + CtrlHandler>( pub(crate) unsafe fn setup_ctrl_handler<T: 'static + CtrlHandler>(
handler: &mut T, handler: *mut T,
) -> Result<(), Error> { ) -> Result<(), Error> {
write_volatile( write_volatile(
&mut CTRL_HANDLER, &mut CTRL_HANDLER,