network: fix SIGSEGV on unknown message acceptance

For example, at the moment our node can't handle `consensus` message, so when
it received it before the patch it just crashed because of uninitialized `p`.
This commit is contained in:
Roman Khimov 2019-09-22 20:09:55 +03:00
parent 4b4bac675b
commit 5a0f08f2c0

View file

@ -3,6 +3,7 @@ package network
import ( import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt"
"github.com/CityOfZion/neo-go/config" "github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core" "github.com/CityOfZion/neo-go/pkg/core"
@ -193,6 +194,8 @@ func (m *Message) decodePayload(br *io.BinReader) error {
p = &transaction.Transaction{} p = &transaction.Transaction{}
case CMDMerkleBlock: case CMDMerkleBlock:
p = &payload.MerkleBlock{} p = &payload.MerkleBlock{}
default:
return fmt.Errorf("can't decode command %s", cmdByteArrayToString(m.Command))
} }
p.DecodeBinary(r) p.DecodeBinary(r)
if r.Err != nil { if r.Err != nil {