diff --git a/src/js.rs b/src/js.rs index 15266ed16..8d06b90f1 100644 --- a/src/js.rs +++ b/src/js.rs @@ -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);