From 71e41d4b0a53442a4ed589983578c0186a94d93a Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 6 May 2022 13:34:59 +0800 Subject: [PATCH] fix buffer length check computation --- services/shellchat/src/cmds/net_cmd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/shellchat/src/cmds/net_cmd.rs b/services/shellchat/src/cmds/net_cmd.rs index 3e80a766a..6defeb943 100644 --- a/services/shellchat/src/cmds/net_cmd.rs +++ b/services/shellchat/src/cmds/net_cmd.rs @@ -103,7 +103,7 @@ impl<'a> ShellCmdApi<'a> for NetCmd { match stream.read(&mut buf) { Ok(len) => { log::trace!("raw response ({}): {:?}", len, &buf[..len]); - write!(ret, "{}", std::string::String::from_utf8_lossy(&buf[..len])).ok(); // let it run off the end + write!(ret, "{}", std::string::String::from_utf8_lossy(&buf[..len.min(buf.len())])).ok(); // let it run off the end } Err(e) => write!(ret, "Didn't get response from host: {:?}", e).unwrap(), } @@ -123,7 +123,7 @@ impl<'a> ShellCmdApi<'a> for NetCmd { let boot_instant = env.boot_instant.clone(); move || { let listener = TcpListener::bind("0.0.0.0:80").unwrap(); - // limit to 2 because we're a bit shy on space in shellchat right now; there is a 32-thread limit per process, and shellchat has the kitchen sink. + // limit to 4 because we're a bit shy on space in shellchat right now; there is a 32-thread limit per process, and shellchat has the kitchen sink. let pool = ThreadPool::new(4); for stream in listener.incoming() {