go.crypto/ssh: sanity check incoming packet length

The check for a sensible packet length was removed a while ago
when the window size and channel packet size checks were moved
into channel.go. While the RFC suggests that any packet of size
less than uint32 -1 is valid, most implmentations limit the size
to a smaller value. OpenSSH chose 256kb, so that sounds like a
sensible default.

R=agl, huin, kardianos
CC=golang-dev
https://golang.org/cl/6490098
This commit is contained in:
Dave Cheney
2012-09-10 06:57:24 +10:00
parent f09bfbbb56
commit 591d65c664
2 changed files with 26 additions and 1 deletions
+10
View File
@@ -435,6 +435,16 @@ func TestClientCannotSendAfterClose(t *testing.T) {
}
}
func TestClientCannotSendHugePacket(t *testing.T) {
// client and server use the same transport write code so this
// test suffices for both.
conn := dial(shellHandler, t)
defer conn.Close()
if err := conn.transport.writePacket(make([]byte, maxPacket*2)); err == nil {
t.Fatalf("huge packet write should fail")
}
}
// windowTestBytes is the number of bytes that we'll send to the SSH server.
const windowTestBytes = 16000 * 200