mirror of
https://github.com/shazow/ssh-chat.git
synced 2026-10-22 23:52:12 +03:00
sshd: Apply read deadline to handler
This commit is contained in:
1 parent
de89c87946
commit
61b525ae54
2 files changed
+7
-5
No files matched your search
@@ -8,3 +8,5 @@ require (
|
||||
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576
|
||||
golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54
|
||||
)
|
||||
|
||||
go 1.13
|
||||
+5
-5
@@ -33,8 +33,11 @@ func (l *SSHListener) handleConn(conn net.Conn) (*Terminal, error) {
|
||||
conn = ReadLimitConn(conn, l.RateLimit())
|
||||
}
|
||||
|
||||
// Handshake shouldn't take more than 10 seconds
|
||||
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||
// If the connection doesn't write anything back for too long before we get
|
||||
// a valid session, it should be dropped.
|
||||
var handleTimeout = 20 * time.Second
|
||||
conn.SetReadDeadline(time.Now().Add(handleTimeout))
|
||||
defer conn.SetReadDeadline(time.Time{})
|
||||
|
||||
// Upgrade TCP connection to SSH connection
|
||||
sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config)
|
||||
@@ -42,9 +45,6 @@ func (l *SSHListener) handleConn(conn net.Conn) (*Terminal, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// clear the deadline
|
||||
conn.SetDeadline(time.Time{})
|
||||
|
||||
// FIXME: Disconnect if too many faulty requests? (Avoid DoS.)
|
||||
go ssh.DiscardRequests(requests)
|
||||
return NewSession(sshConn, channels)
|
||||
|
||||
Reference in new issue
Block a user