fix: maybe hang for process *sshfx.ReadPacket for *Server.handle()"

In `*Server.handle`, if the sshfx.ReadPacket's Length is less than maxDataLen, the client may get stuck during data reading.
This commit is contained in:
cloudsbit 2025-03-25 16:22:03 +08:00
parent 630bb7f768
commit 9033c1b187
1 changed files with 1 additions and 1 deletions

View File

@ -699,7 +699,7 @@ func (srv *Server) handle(req sshfx.Packet, hint []byte, maxDataLen uint32) (ssh
return nil, fmt.Errorf("read length request too large: %d", req.Length)
}
n, err := file.ReadAt(hint, int64(req.Offset))
n, err := file.ReadAt(hint[:req.Length], int64(req.Offset))
if err != nil {
// We cannot return results AND a status like SSH_FX_EOF,
// so we return io.EOF only if we didn't read anything at all.