compiler: check event name length in runtime.Notify

This commit is contained in:
Evgeniy Stratonikov 2021-06-02 11:46:54 +03:00
parent 1a5e656d38
commit 5e92a254b2
2 changed files with 18 additions and 0 deletions

View file

@ -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)
}
}

View file

@ -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) {