Browse Source

Detect non-valid strings for blockheight

Taylor Gerring 10 năm trước cách đây
mục cha
commit
aa71e27a3b
2 tập tin đã thay đổi với 10 bổ sung1 xóa
  1. 5 0
      common/bytes.go
  2. 5 1
      rpc/args.go

+ 5 - 0
common/bytes.go

@@ -127,6 +127,11 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
 	return
 }
 
+func HasHexPrefix(str string) bool {
+	l := len(str)
+	return l >= 2 && str[0:2] == "0x"
+}
+
 func IsHex(str string) bool {
 	l := len(str)
 	return l >= 4 && l%2 == 0 && str[0:2] == "0x"

+ 5 - 1
rpc/args.go

@@ -41,7 +41,11 @@ func blockHeight(raw interface{}, number *int64) error {
 	case "pending":
 		*number = -2
 	default:
-		*number = common.String2Big(str).Int64()
+		if common.HasHexPrefix(str) {
+			*number = common.String2Big(str).Int64()
+		} else {
+			return NewInvalidTypeError("blockNumber", "is not a valid string")
+		}
 	}
 
 	return nil