From d178c965a970e61e3f411e5454ad073d50cad22a Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Sat, 11 Nov 2023 17:53:58 +0000 Subject: [PATCH] Fix UB: Non-static callbacks are unsound --- src/event_bus.rs | 12 ++++++------ src/ping.rs | 8 ++++---- src/timer.rs | 12 ++++++------ src/utils/asyncify/event_bus.rs | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/event_bus.rs b/src/event_bus.rs index 6535389..0a636d9 100644 --- a/src/event_bus.rs +++ b/src/event_bus.rs @@ -51,9 +51,9 @@ pub trait EventBus

: ErrorType { where Self: 'a; - fn subscribe<'a, F>(&'a self, callback: F) -> Result, Self::Error> + fn subscribe(&self, callback: F) -> Result, Self::Error> where - F: FnMut(&P) + Send + 'a; + F: FnMut(&P) + Send + 'static; } impl<'e, P, E> EventBus

for &'e E @@ -62,9 +62,9 @@ where { type Subscription<'a> = E::Subscription<'a> where Self: 'a; - fn subscribe<'a, F>(&'a self, callback: F) -> Result, Self::Error> + fn subscribe(&self, callback: F) -> Result, Self::Error> where - F: FnMut(&P) + Send + 'a, + F: FnMut(&P) + Send + 'static, { (**self).subscribe(callback) } @@ -76,9 +76,9 @@ where { type Subscription<'a> = E::Subscription<'a> where Self: 'a; - fn subscribe<'a, F>(&'a self, callback: F) -> Result, Self::Error> + fn subscribe(&self, callback: F) -> Result, Self::Error> where - F: FnMut(&P) + Send + 'a, + F: FnMut(&P) + Send + 'static, { (**self).subscribe(callback) } diff --git a/src/ping.rs b/src/ping.rs index 0caad5c..a880c0b 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -63,7 +63,7 @@ pub trait Ping { fn ping(&mut self, ip: ipv4::Ipv4Addr, conf: &Configuration) -> Result; - fn ping_details( + fn ping_details( &mut self, ip: ipv4::Ipv4Addr, conf: &Configuration, @@ -81,7 +81,7 @@ where (*self).ping(ip, conf) } - fn ping_details( + fn ping_details( &mut self, ip: ipv4::Ipv4Addr, conf: &Configuration, @@ -107,7 +107,7 @@ pub mod asynch { conf: &Configuration, ) -> Result; - async fn ping_details( + async fn ping_details( &mut self, ip: ipv4::Ipv4Addr, conf: &Configuration, @@ -129,7 +129,7 @@ pub mod asynch { (*self).ping(ip, conf).await } - async fn ping_details( + async fn ping_details( &mut self, ip: ipv4::Ipv4Addr, conf: &Configuration, diff --git a/src/timer.rs b/src/timer.rs index cb44fe3..b47f883 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -72,9 +72,9 @@ pub trait TimerService: ErrorType { where Self: 'a; - fn timer<'a, F>(&'a self, callback: F) -> Result, Self::Error> + fn timer(&self, callback: F) -> Result, Self::Error> where - F: FnMut() + Send + 'a; + F: FnMut() + Send + 'static; } impl TimerService for &S @@ -83,9 +83,9 @@ where { type Timer<'a> = S::Timer<'a> where Self: 'a; - fn timer<'a, F>(&'a self, callback: F) -> Result, Self::Error> + fn timer(&self, callback: F) -> Result, Self::Error> where - F: FnMut() + Send + 'a, + F: FnMut() + Send + 'static, { (*self).timer(callback) } @@ -97,9 +97,9 @@ where { type Timer<'a> = S::Timer<'a> where Self: 'a; - fn timer<'a, F>(&'a self, callback: F) -> Result, Self::Error> + fn timer(&self, callback: F) -> Result, Self::Error> where - F: FnMut() + Send + 'a, + F: FnMut() + Send + 'static, { (**self).timer(callback) } diff --git a/src/utils/asyncify/event_bus.rs b/src/utils/asyncify/event_bus.rs index d824443..a09ca1f 100644 --- a/src/utils/asyncify/event_bus.rs +++ b/src/utils/asyncify/event_bus.rs @@ -187,7 +187,7 @@ where where P: Clone + Send + 'static, E: crate::event_bus::EventBus

, - for<'a> E::Subscription<'a>: Send, + for<'a> E::Subscription<'a>: Send + 'static, { let state = Arc::new(( Mutex::new(SubscriptionState {