diff --git a/x/wasm/types/tx_test.go b/x/wasm/types/tx_test.go index 2e980fd795..52605edba1 100644 --- a/x/wasm/types/tx_test.go +++ b/x/wasm/types/tx_test.go @@ -115,6 +115,42 @@ func TestInstantiateContractValidation(t *testing.T) { }, valid: false, }, + "white space ending label": { + msg: MsgInstantiateContract{ + Sender: goodAddress, + CodeID: firstCodeID, + Label: "foo ", + Msg: []byte("{}"), + }, + valid: false, + }, + "non printable chars ending label": { + msg: MsgInstantiateContract{ + Sender: goodAddress, + CodeID: firstCodeID, + Label: "foo\v", + Msg: []byte("{}"), + }, + valid: false, + }, + "non printable chars in label": { + msg: MsgInstantiateContract{ + Sender: goodAddress, + CodeID: firstCodeID, + Label: "f\voo", + Msg: []byte("{}"), + }, + valid: false, + }, + "non printable chars beginning label": { + msg: MsgInstantiateContract{ + Sender: goodAddress, + CodeID: firstCodeID, + Label: "\vfoo", + Msg: []byte("{}"), + }, + valid: false, + }, "label too long": { msg: MsgInstantiateContract{ Sender: goodAddress, diff --git a/x/wasm/types/validation.go b/x/wasm/types/validation.go index 7282c01e1d..cbdeb77d57 100644 --- a/x/wasm/types/validation.go +++ b/x/wasm/types/validation.go @@ -4,6 +4,7 @@ import ( "fmt" "net/url" "strings" + "unicode" "github.com/docker/distribution/reference" @@ -45,6 +46,15 @@ func ValidateLabel(label string) error { if label != strings.TrimSpace(label) { return ErrInvalid.Wrap("label must not start/end with whitespaces") } + labelWithPrintableCharsOnly := strings.Map(func(r rune) rune { + if unicode.IsPrint(r) { + return r + } + return -1 + }, label) + if label != labelWithPrintableCharsOnly { + return ErrInvalid.Wrap("label must have printable characters only") + } return nil }