From b44fd97af6999e032f71e9e7c265b43163cb4052 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 19 Aug 2019 10:43:09 -0500 Subject: [PATCH] Use host's rng when communication is enabled --- Cargo.toml | 1 + src/helpers.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 644a3476a6d..1ab0580cc63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ byteorder = { version = "1.1", features = ["i128"]} cargo_metadata = { version = "0.8", optional = true } directories = { version = "2.0", optional = true } rustc_version = { version = "0.2.3", optional = true } +getrandom = "0.1.10" env_logger = "0.6" log = "0.4" shell-escape = "0.1.4" diff --git a/src/helpers.rs b/src/helpers.rs index c0e1ec2cd75..d134a19f4c2 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -97,9 +97,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx Align::from_bytes(1).unwrap() )?.expect("we already checked for size 0"); - let rng = this.memory_mut().extra.rng.get_mut(); let mut data = vec![0; len]; - rng.fill_bytes(&mut data); + + if this.machine.communicate { + // Fill the buffer using the host's rng. + getrandom::getrandom(&mut data).map_err(|err| { + InterpError::Unsupported(UnsupportedOpInfo::Unsupported(err.to_string())) + })?; + } + else { + let rng = this.memory_mut().extra.rng.get_mut(); + rng.fill_bytes(&mut data); + } let tcx = &{this.tcx.tcx}; this.memory_mut().get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data)