From aa71e27a3b0f42b980082c52232c68fb50a45052 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 15:53:04 +0200 Subject: [PATCH] Detect non-valid strings for blockheight --- common/bytes.go | 5 +++++ rpc/args.go | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common/bytes.go b/common/bytes.go index 2d885ac746..5bdacd810a 100644 --- a/common/bytes.go +++ b/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" diff --git a/rpc/args.go b/rpc/args.go index a8cb7dcb16..cebabf4ba9 100644 --- a/rpc/args.go +++ b/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