go.crypto/ssh: improve channel max packet handling
This proposal moves the check for max packet into channel.writePacket. Callers should be aware they cannot pass a buffer larger than max packet. This is only a concern to chanWriter.Write and appropriate guards are already in place. There was some max packet handling in transport.go but it was incorrect. This has been removed. This proposal also cleans up session_test.go. R=gustav.paul, agl, fullung, huin CC=golang-dev https://golang.org/cl/6460075
This commit is contained in:
+4
-2
@@ -564,13 +564,15 @@ func (s *ServerConn) Accept() (Channel, error) {
|
||||
default:
|
||||
switch msg := decode(packet).(type) {
|
||||
case *channelOpenMsg:
|
||||
if msg.MaxPacketSize < minPacketLength || msg.MaxPacketSize > 1<<31 {
|
||||
return nil, errors.New("ssh: invalid MaxPacketSize from peer")
|
||||
}
|
||||
c := &serverChan{
|
||||
channel: channel{
|
||||
conn: s,
|
||||
remoteId: msg.PeersId,
|
||||
remoteWin: window{Cond: newCond()},
|
||||
// TODO(dfc) assert this param is < 2^31.
|
||||
maxPacketSize: msg.MaxPacketSize,
|
||||
maxPacket: msg.MaxPacketSize,
|
||||
},
|
||||
chanType: msg.ChanType,
|
||||
extraData: msg.TypeSpecificData,
|
||||
|
||||
Reference in New Issue
Block a user