mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-04 19:19:44 +00:00
rpc/server: limit the maximum number of elements for get*transfers
This commit is contained in:
parent
56d57611ca
commit
010c22e2b5
1 changed files with 8 additions and 0 deletions
|
@ -74,6 +74,9 @@ const (
|
|||
// treated like subscriber, so technically it's a limit on websocket
|
||||
// connections.
|
||||
maxSubscribers = 64
|
||||
|
||||
// Maximum number of elements for get*transfers requests.
|
||||
maxTransfersLimit = 1000
|
||||
)
|
||||
|
||||
var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *response.Error){
|
||||
|
@ -453,6 +456,8 @@ func (s *Server) getVersion(_ request.Params) (interface{}, *response.Error) {
|
|||
func getTimestampsAndLimit(ps request.Params, index int) (uint32, uint32, int, int, error) {
|
||||
var start, end uint32
|
||||
var limit, page int
|
||||
|
||||
limit = maxTransfersLimit
|
||||
pStart, pEnd, pLimit, pPage := ps.Value(index), ps.Value(index+1), ps.Value(index+2), ps.Value(index+3)
|
||||
if pPage != nil {
|
||||
p, err := pPage.GetInt()
|
||||
|
@ -472,6 +477,9 @@ func getTimestampsAndLimit(ps request.Params, index int) (uint32, uint32, int, i
|
|||
if l <= 0 {
|
||||
return 0, 0, 0, 0, errors.New("can't use negative or zero limit")
|
||||
}
|
||||
if l > maxTransfersLimit {
|
||||
return 0, 0, 0, 0, errors.New("too big limit requested")
|
||||
}
|
||||
limit = l
|
||||
}
|
||||
if pEnd != nil {
|
||||
|
|
Loading…
Reference in a new issue