network: use MaxHeadersAllowed to restrict GetBlockByIndex

This commit is contained in:
Anna Shaleva 2020-07-31 14:03:35 +03:00
parent 737ba700e9
commit 0b856033b0
2 changed files with 2 additions and 5 deletions

View file

@ -6,9 +6,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
) )
// maximum number of blocks to query about
const maxBlockCount = 500
// GetBlockByIndex payload // GetBlockByIndex payload
type GetBlockByIndex struct { type GetBlockByIndex struct {
IndexStart uint32 IndexStart uint32
@ -27,7 +24,7 @@ func NewGetBlockByIndex(indexStart uint32, count uint16) *GetBlockByIndex {
func (d *GetBlockByIndex) DecodeBinary(br *io.BinReader) { func (d *GetBlockByIndex) DecodeBinary(br *io.BinReader) {
d.IndexStart = br.ReadU32LE() d.IndexStart = br.ReadU32LE()
d.Count = br.ReadU16LE() d.Count = br.ReadU16LE()
if d.Count == 0 || d.Count > maxBlockCount { if d.Count == 0 || d.Count > MaxHeadersAllowed {
br.Err = errors.New("invalid block count") br.Err = errors.New("invalid block count")
} }
} }

View file

@ -18,7 +18,7 @@ func TestGetBlockDataEncodeDecode(t *testing.T) {
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex))) require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
// invalid block count // invalid block count
d = NewGetBlockByIndex(5, maxBlockCount+1) d = NewGetBlockByIndex(5, MaxHeadersAllowed+1)
data, err = testserdes.EncodeBinary(d) data, err = testserdes.EncodeBinary(d)
require.NoError(t, err) require.NoError(t, err)
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex))) require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))