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:
Martin Holst Swende 2023-08-08 13:35:58 +02:00 committed by GitHub
parent 6d2bcb911a
commit 0d772b9f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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