mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-26 19:43:48 +00:00
compiler: check event name length in runtime.Notify
This commit is contained in:
parent
1a5e656d38
commit
5e92a254b2
2 changed files with 18 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue