diff --git a/pkg/network/message.go b/pkg/network/message.go index a4eeea882..12674698a 100644 --- a/pkg/network/message.go +++ b/pkg/network/message.go @@ -106,7 +106,12 @@ func (m *Message) Decode(br *io.BinReader) error { // check the length first in order not to allocate memory // for an empty compressed payload if l == 0 { - m.Payload = payload.NewNullPayload() + switch m.Command { + case CMDFilterClear, CMDGetAddr, CMDMempool: + m.Payload = payload.NewNullPayload() + default: + return errors.New("unexpected empty payload") + } return nil } if l > PayloadMaxSize { diff --git a/pkg/network/payload/payload.go b/pkg/network/payload/payload.go index 0c295b5d1..a761de2e2 100644 --- a/pkg/network/payload/payload.go +++ b/pkg/network/payload/payload.go @@ -12,12 +12,12 @@ type NullPayload struct { } // NewNullPayload returns zero-sized stub payload. -func NewNullPayload() *NullPayload { - return &NullPayload{} +func NewNullPayload() NullPayload { + return NullPayload{} } // DecodeBinary implements Serializable interface. -func (p *NullPayload) DecodeBinary(r *io.BinReader) {} +func (p NullPayload) DecodeBinary(r *io.BinReader) {} // EncodeBinary implements Serializable interface. -func (p *NullPayload) EncodeBinary(w *io.BinWriter) {} +func (p NullPayload) EncodeBinary(w *io.BinWriter) {}