From f0710ededc80610fdaff3209f8b94fa0d7bb78ce Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 25 Feb 2022 20:16:42 -0500 Subject: ensure read_buf doesn't overflow the buffer --- tests/basic.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/basic.rs') diff --git a/tests/basic.rs b/tests/basic.rs index 6f276e6..ed75e60 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -51,3 +51,36 @@ fn test_cat_async() { }); assert_eq!(status.code().unwrap(), 0); } + +#[cfg(feature = "async")] +#[test] +fn test_yes_async() { + use tokio::io::AsyncReadExt as _; + + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(async { + let mut pty = pty_process::Pty::new().unwrap(); + let pts = pty.pts().unwrap(); + pty.resize(pty_process::Size::new(24, 80)).unwrap(); + let mut child = + pty_process::Command::new("yes").spawn(&pts).unwrap(); + + let mut buf = [0u8; 3]; + + let bytes = pty.read_buf(&mut &mut buf[..]).await.unwrap(); + assert_eq!(&buf[..bytes], b"y\r\n"); + + let (mut pty_r, _pty_w) = pty.split(); + let bytes = pty_r.read_buf(&mut &mut buf[..]).await.unwrap(); + assert_eq!(&buf[..bytes], b"y\r\n"); + + let (mut pty_r, _pty_w) = pty.into_split(); + let bytes = pty_r.read_buf(&mut &mut buf[..]).await.unwrap(); + assert_eq!(&buf[..bytes], b"y\r\n"); + + child.kill().await.unwrap() + }); +} -- cgit v1.2.3-54-g00ecf