From 4122ceac948d280af01b0e91003623217c704e97 Mon Sep 17 00:00:00 2001 From: Warren Date: Mon, 15 Jun 2026 12:20:34 +0800 Subject: [PATCH] Fix SSH PTY request: Correct terminal modes reading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - Interactive SSH connections (ssh markbase) failed with 'Connection reset by peer' - Server error: 'failed to fill whole buffer' when processing pty-req request Root cause: - Terminal modes reading incorrectly used read_ssh_string() - This caused double reading of length field (modes_len already read) - Correct approach: read modes_len bytes directly after reading modes_len Fix: - Changed from: read_ssh_string(cursor) for modes - Changed to: read_exact(&mut modes) after reading modes_len - Fixed typo in pixel_width/pixel_height variable declarations RFC 4253 Section 6.2 PTY request format: string terminal modes (uint32 length + data) We now correctly read the data after the length field Test results: sshpass -p 'demo123' ssh markbase 'whoami && pwd': Success ✓ Interactive SSH session now works correctly ✓ Files modified: - channel.rs: Fixed handle_pty_request() modes reading --- markbase-core/src/ssh_server/channel.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/markbase-core/src/ssh_server/channel.rs b/markbase-core/src/ssh_server/channel.rs index 00f89d0..62258ff 100644 --- a/markbase-core/src/ssh_server/channel.rs +++ b/markbase-core/src/ssh_server/channel.rs @@ -279,20 +279,21 @@ impl ChannelManager { fn handle_pty_request(&mut self, cursor: &mut std::io::Cursor<&[u8]>, channel: u32, want_reply: bool) -> Result> { info!("Handling pty request for channel {}", channel); - // 读取terminal类型 + // 读取terminal类型(SSH string) let term = read_ssh_string(cursor)?; - // 读取窗口大小 +// 读取窗口大小(4个uint32) let width = cursor.read_u32::()?; let height = cursor.read_u32::()?; - let pixel_width = cursor.read_u32::()?; - let pixel_height = cursor.read_u32::()?; + let _pixel_width = cursor.read_u32::()?; + let _pixel_height = cursor.read_u32::()?; - // 读取terminal modes + // 读取terminal modes(SSH string格式) let modes_len = cursor.read_u32::()?; - let modes = read_ssh_string(cursor)?; + let mut modes = vec![0u8; modes_len as usize]; + cursor.read_exact(&mut modes)?; - info!("PTY: term={}, width={}, height={}", term, width, height); + info!("PTY: term={}, width={}, height={}, modes_len={}", term, width, height, modes_len); if want_reply { Ok(Some(self.build_channel_success(channel)?))