Skip to content

Commit aa71e27

Browse files
committed
Detect non-valid strings for blockheight
1 parent 3908590 commit aa71e27

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎common/bytes.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
127127
return
128128
}
129129

130+
func HasHexPrefix(str string) bool {
131+
l := len(str)
132+
return l >= 2 && str[0:2] == "0x"
133+
}
134+
130135
func IsHex(str string) bool {
131136
l := len(str)
132137
return l >= 4 && l%2 == 0 && str[0:2] == "0x"

‎rpc/args.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ func blockHeight(raw interface{}, number *int64) error {
4141
case "pending":
4242
*number = -2
4343
default:
44-
*number = common.String2Big(str).Int64()
44+
if common.HasHexPrefix(str) {
45+
*number = common.String2Big(str).Int64()
46+
} else {
47+
return NewInvalidTypeError("blockNumber", "is not a valid string")
48+
}
4549
}
4650

4751
return nil

0 commit comments

Comments
 (0)