Skip to content

Commit 0505868

Browse files
committed
Do nothing when we try to generate random data of length 0
This preserves compatibility with programs that pass a null pointer and a length of zero to getrandom(), or their platform's equivalent.
1 parent d82b244 commit 0505868

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/helpers.rs

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8181
ptr: Scalar<Tag>,
8282
len: usize,
8383
) -> InterpResult<'tcx> {
84+
// Some programs pass in a null pointer and a length of 0
85+
// to their platform's random-generation function (e.g. getrandom())
86+
// on Linux. For compatibility with these programs, we don't perform
87+
// any additional checks - it's okay if the pointer is invalid,
88+
// since we wouldn't actually be writing to it.
89+
if len == 0 {
90+
return Ok(())
91+
}
8492
let this = self.eval_context_mut();
8593

8694
let ptr = match this.memory().check_ptr_access(ptr, Size::from_bytes(len as u64), Align::from_bytes(1).unwrap())? {

0 commit comments

Comments
 (0)