From 5e92a254b239466cce6fc40de4090a2d54c87ee8 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Wed, 2 Jun 2021 11:46:54 +0300 Subject: [PATCH] compiler: check event name length in `runtime.Notify` --- pkg/compiler/inline.go | 7 +++++++ pkg/compiler/syscall_test.go | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/pkg/compiler/inline.go b/pkg/compiler/inline.go index 7832b6c9d..6c5b676ce 100644 --- a/pkg/compiler/inline.go +++ b/pkg/compiler/inline.go @@ -1,10 +1,12 @@ package compiler import ( + "fmt" "go/ast" "go/constant" "go/types" + "github.com/nspcc-dev/neo-go/pkg/core/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" ) @@ -134,6 +136,11 @@ func (c *codegen) processNotify(f *funcScope, args []ast.Expr) { } name := constant.StringVal(tv.Value) + if len(name) > runtime.MaxEventNameLen { + c.prog.Err = fmt.Errorf("event name '%s' should be less than %d", + name, runtime.MaxEventNameLen) + return + } c.emittedEvents[name] = append(c.emittedEvents[name], params) } } diff --git a/pkg/compiler/syscall_test.go b/pkg/compiler/syscall_test.go index 86adb3306..048362af2 100644 --- a/pkg/compiler/syscall_test.go +++ b/pkg/compiler/syscall_test.go @@ -188,6 +188,17 @@ func TestNotify(t *testing.T) { assert.Equal(t, exp0, s.events[0].Item.Value()) assert.Equal(t, "single", s.events[1].Name) assert.Equal(t, []stackitem.Item{}, s.events[1].Item.Value()) + + t.Run("long event name", func(t *testing.T) { + src := `package foo + import "github.com/nspcc-dev/neo-go/pkg/interop/runtime" + func Main(arg int) { + runtime.Notify("long event12345678901234567890123") + }` + + _, _, err := compiler.CompileWithDebugInfo("foo.go", strings.NewReader(src)) + require.Error(t, err) + }) } func TestSyscallInGlobalInit(t *testing.T) {