Actually close connection based on unknown protocol version
This commit is contained in:
parent
c111ed4b20
commit
8c32955da1
|
@ -356,6 +356,11 @@ func (c *rawConnection) readMessage() (hdr header, msg encodable, err error) {
|
||||||
l.Debugf("read header %v (msglen=%d)", hdr, msglen)
|
l.Debugf("read header %v (msglen=%d)", hdr, msglen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hdr.version != 0 {
|
||||||
|
err = fmt.Errorf("unknown protocol version 0x%x", hdr.version)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if cap(c.rdbuf0) < msglen {
|
if cap(c.rdbuf0) < msglen {
|
||||||
c.rdbuf0 = make([]byte, msglen)
|
c.rdbuf0 = make([]byte, msglen)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -189,7 +189,7 @@ func TestVersionErr(t *testing.T) {
|
||||||
msgID: 0,
|
msgID: 0,
|
||||||
msgType: 0,
|
msgType: 0,
|
||||||
}))
|
}))
|
||||||
w.WriteUint32(0)
|
w.WriteUint32(0) // Avoids reader closing due to EOF
|
||||||
|
|
||||||
if !m1.isClosed() {
|
if !m1.isClosed() {
|
||||||
t.Error("Connection should close due to unknown version")
|
t.Error("Connection should close due to unknown version")
|
||||||
|
@ -212,7 +212,7 @@ func TestTypeErr(t *testing.T) {
|
||||||
msgID: 0,
|
msgID: 0,
|
||||||
msgType: 42,
|
msgType: 42,
|
||||||
}))
|
}))
|
||||||
w.WriteUint32(0)
|
w.WriteUint32(0) // Avoids reader closing due to EOF
|
||||||
|
|
||||||
if !m1.isClosed() {
|
if !m1.isClosed() {
|
||||||
t.Error("Connection should close due to unknown message type")
|
t.Error("Connection should close due to unknown message type")
|
||||||
|
|
Loading…
Reference in New Issue