forked from TrueCloudLab/neoneo-go
core: adjust System.Runtime.Log interop
Part of #1055 and #1198. It should check the message length and encoding.
This commit is contained in:
parent
76acef18ad
commit
2c41b7b254
1 changed files with 11 additions and 1 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
|
@ -29,6 +30,8 @@ const (
|
||||||
MaxTraceableBlocks = transaction.MaxValidUntilBlockIncrement
|
MaxTraceableBlocks = transaction.MaxValidUntilBlockIncrement
|
||||||
// MaxEventNameLen is the maximum length of a name for event.
|
// MaxEventNameLen is the maximum length of a name for event.
|
||||||
MaxEventNameLen = 32
|
MaxEventNameLen = 32
|
||||||
|
// MaxNotificationSize is the maximum length of a runtime log message.
|
||||||
|
MaxNotificationSize = 1024
|
||||||
)
|
)
|
||||||
|
|
||||||
// StorageContext contains storing id and read/write flag, it's used as
|
// StorageContext contains storing id and read/write flag, it's used as
|
||||||
|
@ -272,7 +275,14 @@ func runtimeNotify(ic *interop.Context, v *vm.VM) error {
|
||||||
|
|
||||||
// runtimeLog logs the message passed.
|
// runtimeLog logs the message passed.
|
||||||
func runtimeLog(ic *interop.Context, v *vm.VM) error {
|
func runtimeLog(ic *interop.Context, v *vm.VM) error {
|
||||||
msg := fmt.Sprintf("%q", v.Estack().Pop().Bytes())
|
state := v.Estack().Pop().Bytes()
|
||||||
|
if len(state) > MaxNotificationSize {
|
||||||
|
return fmt.Errorf("message length shouldn't exceed %v", MaxNotificationSize)
|
||||||
|
}
|
||||||
|
if !utf8.Valid(state) {
|
||||||
|
return errors.New("log message should be UTF8-encoded")
|
||||||
|
}
|
||||||
|
msg := fmt.Sprintf("%q", state)
|
||||||
ic.Log.Info("runtime log",
|
ic.Log.Info("runtime log",
|
||||||
zap.Stringer("script", v.GetCurrentScriptHash()),
|
zap.Stringer("script", v.GetCurrentScriptHash()),
|
||||||
zap.String("logs", msg))
|
zap.String("logs", msg))
|
||||||
|
|
Loading…
Reference in a new issue