network: allow NullPayload only for specific commands

CMDFilterClear, CMDGetAddr, CMDMempool all have empty payloads.
This commit is contained in:
Evgenii Stratonikov 2020-06-19 11:18:43 +03:00
parent 025bf9c235
commit 9f42108ef2

View file

@ -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 {
switch m.Command {
case CMDFilterClear, CMDGetAddr, CMDMempool:
m.Payload = payload.NewNullPayload()
default:
return errors.New("unexpected empty payload")
}
return nil
}
if l > PayloadMaxSize {