kitsuneninetails / signal-rust Goto Github PK
View Code? Open in Web Editor NEWSignal Handling in Rust
License: MIT License
Signal Handling in Rust
License: MIT License
Hello! As part of rust-lang/rust#99389 I'm going through crates that run into stricter checks that are being added, and this crate runs into them.
In signal.rs
, the uninitialized::<libc::sigaction>()
should use mem::zeroed or MaybeUninit, or directly constructing the struct. Not sure what you want to do, but uninitialized
is UB.
Anywhere else that uninitialized
is being used is also UB, but might not panic just yet, but might in the future.
Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed that the SyncChannel
object implements Send
and Sync
unconiditionally:
Lines 58 to 59 in 2d671bd
However, this should probably be bounded by T: Send in both, otherwise it allows sending types that should never be sent across threads such as Rc or references to cells. You can see an example of such a data-race with cells below:
#![forbid(unsafe_code)]
use signal_simple::channel::SyncChannel;
use std::cell::Cell;
use crossbeam_utils::thread;
// A simple tagged union used to demonstrate problems with data races in Cell.
#[derive(Debug, Clone, Copy)]
enum RefOrInt { Ref(&'static u64), Int(u64) }
static SOME_INT: u64 = 123;
fn main() {
let cell = Cell::new(RefOrInt::Ref(&SOME_INT));
let channel = SyncChannel::new();
channel.send(&cell);
thread::scope(|s| {
s.spawn(|_| {
let smuggled_cell = channel.recv().unwrap();
loop {
// Repeatedly write Ref(&addr) and Int(0xdeadbeef) into the cell.
smuggled_cell.set(RefOrInt::Ref(&SOME_INT));
smuggled_cell.set(RefOrInt::Int(0xdeadbeef));
}
});
loop {
if let RefOrInt::Ref(addr) = cell.get() {
// Hope that between the time we pattern match the object as a
// `Ref`, it gets written to by the other thread.
if addr as *const u64 == &SOME_INT as *const u64 { continue; }
println!("Pointer is now: {:p}", addr);
println!("Dereferencing addr will now segfault: {}", *addr);
}
}
});
}
which outputs:
Pointer is now: 0xdeadbeef
Return Code: -11 (SIGSEGV)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.