diff --git a/src/shims/posix/foreign_items.rs b/src/shims/posix/foreign_items.rs index bbda40def620..8efe8f0ed3fd 100644 --- a/src/shims/posix/foreign_items.rs +++ b/src/shims/posix/foreign_items.rs @@ -67,7 +67,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let buf = this.read_scalar(buf)?.not_undef()?; let count = this.read_scalar(count)?.to_machine_usize(this)?; let result = if fd == 0 { - throw_unsup_format!("reading from stdin is not implemented") + use std::io::{self, Read}; + + let mut buffer = String::new(); + let res = io::stdin().read_to_string(&mut buffer); + + match res { + Ok(bytes) => { + this.memory.write_bytes(buf, buffer.bytes())?; + i64::try_from(bytes).unwrap() + }, + Err(_) => -1, + } } else if fd == 1 || fd == 2 { throw_unsup_format!("cannot read from stdout/stderr") } else {