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>
pull/27887/head
Martin Holst Swende 1 year ago committed by GitHub
parent 6d2bcb911a
commit 0d772b9f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      graphql/graphql.go

@ -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{
@ -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
}

Loading…
Cancel
Save