From 2c41b7b25400745b0f2dbd42fa01fd244bb32f19 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 21 Jul 2020 15:26:12 +0300 Subject: [PATCH] core: adjust System.Runtime.Log interop Part of #1055 and #1198. It should check the message length and encoding. --- pkg/core/interop_system.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 17f6b00bd..fd0fb96e8 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -6,6 +6,7 @@ import ( "fmt" "math" "math/big" + "unicode/utf8" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/blockchainer" @@ -29,6 +30,8 @@ const ( MaxTraceableBlocks = transaction.MaxValidUntilBlockIncrement // MaxEventNameLen is the maximum length of a name for event. 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 @@ -272,7 +275,14 @@ func runtimeNotify(ic *interop.Context, v *vm.VM) error { // runtimeLog logs the message passed. 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", zap.Stringer("script", v.GetCurrentScriptHash()), zap.String("logs", msg))