Narsil / rdev

Simple library to listen and send events to keyboard and mouse (MacOS, Windows, Linux)
MIT License
503 stars 124 forks source link

Thread safety violation in `windows::grab::grab` #123

Open OpatrilPeter opened 9 months ago

OpatrilPeter commented 9 months ago

Hi, I was randomly browsing your repo and the line

GLOBAL_CALLBACK = Some(Box::new(callback));

struck me. There's no synchronization when modifying this static mut and it's code directly reachable from client code, making it thread unsafe.

I'd recommend to add a mutex or mark that function unsafe. If you plan to keep it safe, I'd also recommend making sure the raw_callback is aware of callback change too. Checking if this idiom isn't used incorrectly elsewhere might help too.