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:
+1
-10
@@ -19,9 +19,6 @@ import (
|
||||
|
||||
const (
|
||||
packetSizeMultiple = 16 // TODO(huin) this should be determined by the cipher.
|
||||
minPacketSize = 16
|
||||
maxPacketSize = 36000
|
||||
minPaddingSize = 4 // TODO(huin) should this be configurable?
|
||||
)
|
||||
|
||||
// conn represents an ssh transport that implements packet based
|
||||
@@ -97,9 +94,6 @@ func (r *reader) readOnePacket() ([]byte, error) {
|
||||
if length <= paddingLength+1 {
|
||||
return nil, errors.New("ssh: invalid packet length")
|
||||
}
|
||||
if length > maxPacketSize {
|
||||
return nil, errors.New("ssh: packet too large")
|
||||
}
|
||||
|
||||
packet := make([]byte, length-1+macSize)
|
||||
if _, err := io.ReadFull(r, packet); err != nil {
|
||||
@@ -196,11 +190,8 @@ func (w *writer) writePacket(packet []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := w.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
w.seqNum++
|
||||
return err
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
// Send a message to the remote peer
|
||||
|
||||
Reference in New Issue
Block a user