payload: limit the user agent field in version payload

Protocol limit.
This commit is contained in:
Roman Khimov 2020-10-07 18:27:24 +03:00
parent 705941a800
commit f318e573d4

View file

@ -8,6 +8,9 @@ import (
"github.com/nspcc-dev/neo-go/pkg/network/capability" "github.com/nspcc-dev/neo-go/pkg/network/capability"
) )
// MaxUserAgentLength is the limit for user agent field.
const MaxUserAgentLength = 1024
// Version payload. // Version payload.
type Version struct { type Version struct {
// NetMode of the node // NetMode of the node
@ -42,7 +45,7 @@ func (p *Version) DecodeBinary(br *io.BinReader) {
p.Version = br.ReadU32LE() p.Version = br.ReadU32LE()
p.Timestamp = br.ReadU32LE() p.Timestamp = br.ReadU32LE()
p.Nonce = br.ReadU32LE() p.Nonce = br.ReadU32LE()
p.UserAgent = br.ReadVarBytes() p.UserAgent = br.ReadVarBytes(MaxUserAgentLength)
p.Capabilities.DecodeBinary(br) p.Capabilities.DecodeBinary(br)
} }