Skip to content

Commit 0d772b9

Browse files
holimans1na
andauthored
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>
1 parent 6d2bcb9 commit 0d772b9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

graphql/graphql.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
12501250
if to < from {
12511251
return []*Block{}, nil
12521252
}
1253-
ret := make([]*Block, 0, to-from+1)
1253+
var ret []*Block
12541254
for i := from; i <= to; i++ {
12551255
numberOrHash := rpc.BlockNumberOrHashWithNumber(i)
12561256
block := &Block{
@@ -1268,6 +1268,9 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
12681268
break
12691269
}
12701270
ret = append(ret, block)
1271+
if err := ctx.Err(); err != nil {
1272+
return nil, err
1273+
}
12711274
}
12721275
return ret, nil
12731276
}

0 commit comments

Comments
 (0)