Validate that FromBlock/ToBlock epoch is indeed a hex value (#10780)

* Validate that FromBlock/ToBlock epoch is indeed a hex value

* Adding tests
This commit is contained in:
Friðrik Ásmundsson
2023-05-09 17:17:23 -04:00
committed by GitHub
parent 5c26a3da1f
commit ceb3f1e41e
3 changed files with 14 additions and 2 deletions
+7
View File
@@ -9,6 +9,7 @@ import (
"os"
"sort"
"strconv"
"strings"
"sync"
"time"
@@ -1180,6 +1181,9 @@ func (e *EthEvent) installEthFilterSpec(ctx context.Context, filterSpec *ethtype
} else if *filterSpec.FromBlock == "pending" {
return nil, api.ErrNotSupported
} else {
if !strings.HasPrefix(*filterSpec.FromBlock, "0x") {
return nil, xerrors.Errorf("FromBlock is not a hex")
}
epoch, err := ethtypes.EthUint64FromHex(*filterSpec.FromBlock)
if err != nil {
return nil, xerrors.Errorf("invalid epoch")
@@ -1195,6 +1199,9 @@ func (e *EthEvent) installEthFilterSpec(ctx context.Context, filterSpec *ethtype
} else if *filterSpec.ToBlock == "pending" {
return nil, api.ErrNotSupported
} else {
if !strings.HasPrefix(*filterSpec.ToBlock, "0x") {
return nil, xerrors.Errorf("ToBlock is not a hex")
}
epoch, err := ethtypes.EthUint64FromHex(*filterSpec.ToBlock)
if err != nil {
return nil, xerrors.Errorf("invalid epoch")