Prechádzať zdrojové kódy

go.crypto/ssh: fix panic unmarshalling channelOpenFailureMsg

I introduced this problem in change set 33 when I redefined
RejectionReason from a uint32 to an int. I have added a test
to verify the message can be marshaled correctly.

This was a bit hard to track down as the recover in clientConn
mainLoop would catch the panic and shutdown the connection. We
probably shouldn't be using panic inside marshal/unmarshal, at
least not without a way to let the user know why the recover
logic tripped.

R=agl, kardianos, gustav.paul
CC=golang-dev
https://golang.org/cl/6210063
Dave Cheney 13 rokov pred
rodič
commit
36d74d6fed
2 zmenil súbory, kde vykonal 9 pridanie a 1 odobranie
  1. 1 1
      ssh/channel.go
  2. 8 0
      ssh/messages_test.go

+ 1 - 1
ssh/channel.go

@@ -61,7 +61,7 @@ func (c ChannelRequest) Error() string {
 
 
 // RejectionReason is an enumeration used when rejecting channel creation
 // RejectionReason is an enumeration used when rejecting channel creation
 // requests. See RFC 4254, section 5.1.
 // requests. See RFC 4254, section 5.1.
-type RejectionReason int
+type RejectionReason uint32
 
 
 const (
 const (
 	Prohibited RejectionReason = iota + 1
 	Prohibited RejectionReason = iota + 1

+ 8 - 0
ssh/messages_test.go

@@ -40,6 +40,7 @@ var messageTypes = []interface{}{
 	&userAuthRequestMsg{},
 	&userAuthRequestMsg{},
 	&channelOpenMsg{},
 	&channelOpenMsg{},
 	&channelOpenConfirmMsg{},
 	&channelOpenConfirmMsg{},
+	&channelOpenFailureMsg{},
 	&channelRequestMsg{},
 	&channelRequestMsg{},
 	&channelRequestSuccessMsg{},
 	&channelRequestSuccessMsg{},
 }
 }
@@ -124,6 +125,13 @@ func (*kexDHInitMsg) Generate(rand *rand.Rand, size int) reflect.Value {
 	return reflect.ValueOf(dhi)
 	return reflect.ValueOf(dhi)
 }
 }
 
 
+// TODO(dfc) maybe this can be removed in the future if testing/quick can handle
+// derived basic types.
+func (RejectionReason) Generate(rand *rand.Rand, size int) reflect.Value {
+	m := RejectionReason(Prohibited)
+	return reflect.ValueOf(m)
+}
+
 var (
 var (
 	_kexInitMsg   = new(kexInitMsg).Generate(rand.New(rand.NewSource(0)), 10).Elem().Interface()
 	_kexInitMsg   = new(kexInitMsg).Generate(rand.New(rand.NewSource(0)), 10).Elem().Interface()
 	_kexDHInitMsg = new(kexDHInitMsg).Generate(rand.New(rand.NewSource(0)), 10).Elem().Interface()
 	_kexDHInitMsg = new(kexDHInitMsg).Generate(rand.New(rand.NewSource(0)), 10).Elem().Interface()