bound check on protocol message receipt

and some refactoring to extract protocol message payload in common place
This commit is contained in:
Matthias Radestock committed 2015-01-20 20:06:29 +00:00
1 parent 1b3d65476c
commit 5dd62b2ecf
1 file changed
+8 -3
+8 -3
View File
@@ -479,6 +479,11 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
// the traffic rather than shutting down. // the traffic rather than shutting down.
continue continue
} }
if len(msg) < 1 {
conn.log("ignoring blank msg")
continue
}
payload := msg[1:]
switch msg[0] { switch msg[0] {
case ProtocolConnectionEstablished: case ProtocolConnectionEstablished:
// We sent fast heartbeats to the remote peer, which has // We sent fast heartbeats to the remote peer, which has
@@ -496,7 +501,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
conn.setStackFrag(true) conn.setStackFrag(true)
case ProtocolNonce: case ProtocolNonce:
if usingPassword { if usingPassword {
conn.Decryptor.ReceiveNonce(msg[1:]) conn.Decryptor.ReceiveNonce(payload)
} else { } else {
conn.log("ignoring unexpected nonce on unencrypted connection") conn.log("ignoring unexpected nonce on unencrypted connection")
} }
@@ -515,7 +520,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
// out to all its connections an "improved" update. // out to all its connections an "improved" update.
conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Peers.EncodeAllPeers())) conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Peers.EncodeAllPeers()))
case ProtocolUpdate: case ProtocolUpdate:
newUpdate, err := conn.Router.Peers.ApplyUpdate(msg[1:]) newUpdate, err := conn.Router.Peers.ApplyUpdate(payload)
if _, ok := err.(UnknownPeersError); err != nil && ok { if _, ok := err.(UnknownPeersError); err != nil && ok {
// That update contained a peer we didn't know about; // That update contained a peer we didn't know about;
// request full update // request full update
@@ -531,7 +536,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
conn.Router.Ourself.BroadcastTCP(Concat(ProtocolUpdateByte, newUpdate)) conn.Router.Ourself.BroadcastTCP(Concat(ProtocolUpdateByte, newUpdate))
} }
case ProtocolPMTUVerified: case ProtocolPMTUVerified:
conn.verifyPMTU <- int(binary.BigEndian.Uint16(msg[1:])) conn.verifyPMTU <- int(binary.BigEndian.Uint16(payload))
default: default:
conn.log("received unknown msg:\n", msg) conn.log("received unknown msg:\n", msg)
} }