@@ -205,6 +205,9 @@ pub use crate::error::Error;
205205//
206206// These should all provide getrandom_inner with the signature
207207// `fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error>`.
208+ // The function MUST fully initialize `dest` when `Ok(())` is returned.
209+ // The function MUST NOT ever write uninitialized bytes into `dest`,
210+ // regardless of what value it returns.
208211cfg_if ! {
209212 if #[ cfg( any( target_os = "emscripten" , target_os = "haiku" ,
210213 target_os = "redox" ) ) ] {
@@ -290,8 +293,11 @@ cfg_if! {
290293/// [`rand::thread_rng`](https://docs.rs/rand/*/rand/fn.thread_rng.html).
291294#[ inline]
292295pub fn getrandom ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
293- // SAFETY: The `&mut MaybeUninit<_>` reference doesn't escape.
294- getrandom_uninit_slice ( unsafe { slice_as_uninit_mut ( dest) } ) . map ( |_| ( ) )
296+ // SAFETY: The `&mut MaybeUninit<_>` reference doesn't escape, and
297+ // `getrandom_uninit_slice` guarantees it will never de-initialize any
298+ // part of `dest`.
299+ getrandom_uninit_slice ( unsafe { slice_as_uninit_mut ( dest) } ) ?;
300+ Ok ( ( ) )
295301}
296302
297303/// Version of the `getrandom` function which fills `dest` with random bytes
@@ -302,6 +308,9 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
302308/// In other words, it's safe to assume that `dest` is initialized after
303309/// this function has returned `Ok`.
304310///
311+ /// No part of `dest` will ever be de-initialized at any point, regardless
312+ /// of what is returned.
313+ ///
305314/// # Examples
306315///
307316/// ```ignore
0 commit comments