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:
Dave Cheney
2012-08-13 08:22:53 +10:00
parent be3c8d448b
commit 7343d5f584
4 changed files with 126 additions and 76 deletions
+4 -2
View File
@@ -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,