Skip to content

Commit

Permalink
graphql: avoid greedy allocation (#27873)
Browse files Browse the repository at this point in the history
Fixes a graphql-dos

---------

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
  • Loading branch information
3 people authored Aug 8, 2023
1 parent 6d2bcb9 commit 0d772b9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
if to < from {
return []*Block{}, nil
}
ret := make([]*Block, 0, to-from+1)
var ret []*Block
for i := from; i <= to; i++ {
numberOrHash := rpc.BlockNumberOrHashWithNumber(i)
block := &Block{
Expand All @@ -1268,6 +1268,9 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
break
}
ret = append(ret, block)
if err := ctx.Err(); err != nil {
return nil, err
}
}
return ret, nil
}
Expand Down

0 comments on commit 0d772b9

Please # to comment.