graphql: avoid greedy allocation (#27873)
Fixes a graphql-dos --------- Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com> Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
This commit is contained in:
parent
6d2bcb911a
commit
0d772b9f09
@ -1250,7 +1250,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
|
|||||||
if to < from {
|
if to < from {
|
||||||
return []*Block{}, nil
|
return []*Block{}, nil
|
||||||
}
|
}
|
||||||
ret := make([]*Block, 0, to-from+1)
|
var ret []*Block
|
||||||
for i := from; i <= to; i++ {
|
for i := from; i <= to; i++ {
|
||||||
numberOrHash := rpc.BlockNumberOrHashWithNumber(i)
|
numberOrHash := rpc.BlockNumberOrHashWithNumber(i)
|
||||||
block := &Block{
|
block := &Block{
|
||||||
@ -1268,6 +1268,9 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
ret = append(ret, block)
|
ret = append(ret, block)
|
||||||
|
if err := ctx.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user