Unverified Commit 0d772b9f authored by Martin Holst Swende's avatar Martin Holst Swende Committed by GitHub

graphql: avoid greedy allocation (#27873)

Fixes a graphql-dos

---------
Co-authored-by: 's avatarSina Mahmoodi <1591639+s1na@users.noreply.github.com>
Co-authored-by: 's avatarSina Mahmoodi <itz.s1na@gmail.com>
parent 6d2bcb91
...@@ -1250,7 +1250,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct { ...@@ -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 { ...@@ -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
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment