Skip to content

Commit 102a521

Browse files
authored
Initialize dst with zeros in the Node backend
1 parent 0419762 commit 102a521

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/js.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ pub(crate) unsafe fn getrandom_inner(mut dst: *mut u8, mut len: usize) -> Result
3333

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

0 commit comments

Comments
 (0)