Skip to content

Commit 24e5886

Browse files
committed
bsd_arandom: Read only 256 bytes at a time
Older NetBSD kernels cannot handle buffers bigger than 256 bytes, and all FreeBSD and NetBSD kernels only return up to 256 bytes per call. Signed-off-by: Joe Richey <[email protected]>
1 parent fc83790 commit 24e5886

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/bsd_arandom.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
4343
return sys_fill_exact(dest, |buf| unsafe { func(buf.as_mut_ptr(), buf.len(), 0) });
4444
}
4545
}
46-
sys_fill_exact(dest, kern_arnd)
46+
// Both FreeBSD and NetBSD will only return up to 256 bytes at a time, and
47+
// older NetBSD kernels will fail on longer buffers.
48+
for chunk in dest.chunks_mut(256) {
49+
sys_fill_exact(chunk, kern_arnd)?
50+
}
51+
Ok(())
4752
}

0 commit comments

Comments
 (0)