mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 13:47:19 +00:00
smartcontract: disallow Null and non-utf8 String
Follow the https://github.com/neo-project/neo/pull/2810#discussion_r1295900728. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
ed2c4b0319
commit
bb2a99d451
2 changed files with 26 additions and 21 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
|
@ -203,8 +204,10 @@ func (pt ParamType) Match(v stackitem.Item) bool {
|
|||
return vt == stackitem.BooleanT
|
||||
case IntegerType:
|
||||
return vt == stackitem.IntegerT
|
||||
case ByteArrayType, StringType:
|
||||
case ByteArrayType:
|
||||
return vt == stackitem.ByteArrayT || vt == stackitem.BufferT || vt == stackitem.AnyT
|
||||
case StringType:
|
||||
return (vt == stackitem.ByteArrayT || vt == stackitem.BufferT) && utf8.Valid(v.Value().([]byte))
|
||||
case Hash160Type:
|
||||
return checkBytesWithLen(vt, v, Hash160Len)
|
||||
case Hash256Type:
|
||||
|
|
|
@ -428,25 +428,27 @@ func TestConvertToStackitemType(t *testing.T) {
|
|||
|
||||
func TestParamTypeMatch(t *testing.T) {
|
||||
for itm, pt := range map[stackitem.Item]ParamType{
|
||||
&stackitem.Pointer{}: BoolType,
|
||||
&stackitem.Pointer{}: MapType,
|
||||
stackitem.Make(0): BoolType,
|
||||
stackitem.Make(0): ByteArrayType,
|
||||
stackitem.Make(0): StringType,
|
||||
stackitem.Make(false): ByteArrayType,
|
||||
stackitem.Make(true): StringType,
|
||||
stackitem.Make([]byte{1}): Hash160Type,
|
||||
stackitem.Make([]byte{1}): Hash256Type,
|
||||
stackitem.Make([]byte{1}): PublicKeyType,
|
||||
stackitem.Make([]byte{1}): SignatureType,
|
||||
stackitem.Make(0): Hash160Type,
|
||||
stackitem.Make(0): Hash256Type,
|
||||
stackitem.Make(0): PublicKeyType,
|
||||
stackitem.Make(0): SignatureType,
|
||||
stackitem.Make(0): ArrayType,
|
||||
stackitem.Make(0): MapType,
|
||||
stackitem.Make(0): InteropInterfaceType,
|
||||
stackitem.Make(0): VoidType,
|
||||
&stackitem.Pointer{}: BoolType,
|
||||
&stackitem.Pointer{}: MapType,
|
||||
stackitem.Make(0): BoolType,
|
||||
stackitem.Make(0): ByteArrayType,
|
||||
stackitem.Make(0): StringType,
|
||||
stackitem.Make(false): ByteArrayType,
|
||||
stackitem.Make(true): StringType,
|
||||
stackitem.Make([]byte{1}): Hash160Type,
|
||||
stackitem.Make([]byte{1}): Hash256Type,
|
||||
stackitem.Make([]byte{1}): PublicKeyType,
|
||||
stackitem.Make([]byte{1}): SignatureType,
|
||||
stackitem.Make(0): Hash160Type,
|
||||
stackitem.Make(0): Hash256Type,
|
||||
stackitem.Make(0): PublicKeyType,
|
||||
stackitem.Make(0): SignatureType,
|
||||
stackitem.Make(0): ArrayType,
|
||||
stackitem.Make(0): MapType,
|
||||
stackitem.Make(0): InteropInterfaceType,
|
||||
stackitem.Make(0): VoidType,
|
||||
stackitem.Null{}: StringType,
|
||||
stackitem.Make([]byte{0x80}): StringType, // non utf-8
|
||||
} {
|
||||
require.Falsef(t, pt.Match(itm), "%s - %s", pt.String(), itm.String())
|
||||
}
|
||||
|
@ -456,11 +458,11 @@ func TestParamTypeMatch(t *testing.T) {
|
|||
stackitem.Make(0): IntegerType,
|
||||
stackitem.Make(100500): IntegerType,
|
||||
stackitem.Make([]byte{1}): ByteArrayType,
|
||||
stackitem.Make([]byte{0x80}): ByteArrayType, // non utf-8
|
||||
stackitem.Make([]byte{1}): StringType,
|
||||
stackitem.NewBuffer([]byte{1}): ByteArrayType,
|
||||
stackitem.NewBuffer([]byte{1}): StringType,
|
||||
stackitem.Null{}: ByteArrayType,
|
||||
stackitem.Null{}: StringType,
|
||||
stackitem.Make(util.Uint160{}.BytesBE()): Hash160Type,
|
||||
stackitem.Make(util.Uint256{}.BytesBE()): Hash256Type,
|
||||
stackitem.Null{}: Hash160Type,
|
||||
|
|
Loading…
Reference in a new issue