Skip to content

Commit

Permalink
Initialize dst with zeros in the Node backend
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Aug 18, 2022
1 parent 0419762 commit 102a521
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js.rs
Expand Up @@ -33,6 +33,9 @@ pub(crate) unsafe fn getrandom_inner(mut dst: *mut u8, mut len: usize) -> Result

match source {
RngSource::Node(n) => {
// We have to create a slice to pass it to the Node function.
// Since `dst` may be uninitialized, we have to initialize it first.
core::ptr::write_bytes(dst, 0, len);
let dst = core::slice::from_raw_parts_mut(dst, len);
if n.random_fill_sync(dst).is_err() {
return Err(Error::NODE_RANDOM_FILL_SYNC);
Expand Down

0 comments on commit 102a521

Please sign in to comment.