-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use rand's SmallRng for random number generation #141
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit, but otherwise LGTM.
src/util.rs
Outdated
use std::{io, str}; | ||
|
||
use crate::error::IoResultExt; | ||
|
||
thread_local! { | ||
static THREAD_RNG_KEY: Rc<UnsafeCell<SmallRng>> = Rc::new(UnsafeCell::new(SmallRng::from_entropy())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can drop the Rc, right? Just use THREAD_RNG_KEY.with(|rng| use rng...)
.
@Stebalien sorry I totally spaced on getting those changes in, thanks so much for merging! |
This patch does two things 1. Reverts Stebalien#141 by removing handspun SmallRng thread_rng that used unsafe *note Was it a security vulnerability to use a non CSPRNG for tempfiles? 2. Replace use of str::from_utf8_unchecked with char::encode_utf8 Examining the assembly shows no panics generated from encode_utf8 The only functional differences of this patch is replacing SmallRng with a slightly slower RNG and purging unsafe code from a module
#119 seems to have not been updated, so here's another take at it, trying to keep the diff as small as possible.
This approach stores a
SmallRng
as a thread-local variable, basically directly copying the wayrand
does its ownthread_rng()
so as to avoid any issues or incompatibilities.I opted not to further change the way that the
OsString
is built since that feels like it may be better in another PR.