mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
network: use MaxHeadersAllowed to restrict GetBlockByIndex
This commit is contained in:
parent
737ba700e9
commit
0b856033b0
2 changed files with 2 additions and 5 deletions
|
@ -6,9 +6,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
)
|
||||
|
||||
// maximum number of blocks to query about
|
||||
const maxBlockCount = 500
|
||||
|
||||
// GetBlockByIndex payload
|
||||
type GetBlockByIndex struct {
|
||||
IndexStart uint32
|
||||
|
@ -27,7 +24,7 @@ func NewGetBlockByIndex(indexStart uint32, count uint16) *GetBlockByIndex {
|
|||
func (d *GetBlockByIndex) DecodeBinary(br *io.BinReader) {
|
||||
d.IndexStart = br.ReadU32LE()
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestGetBlockDataEncodeDecode(t *testing.T) {
|
|||
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
|
||||
|
||||
// invalid block count
|
||||
d = NewGetBlockByIndex(5, maxBlockCount+1)
|
||||
d = NewGetBlockByIndex(5, MaxHeadersAllowed+1)
|
||||
data, err = testserdes.EncodeBinary(d)
|
||||
require.NoError(t, err)
|
||||
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
|
||||
|
|
Loading…
Reference in a new issue