From 003daf37cfc94687a53726a3acfe07339a2ed275 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 25 Jun 2020 17:32:58 +0300 Subject: [PATCH] vm/cli: add parameter checks for load* commands Prevent failing like this: NEO-GO-VM > loadhex panic: runtime error: index out of range ... --- pkg/vm/cli/cli.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/vm/cli/cli.go b/pkg/vm/cli/cli.go index 6355491c6..29615c58b 100644 --- a/pkg/vm/cli/cli.go +++ b/pkg/vm/cli/cli.go @@ -243,6 +243,10 @@ func handleXStack(c *ishell.Context) { func handleLoadAVM(c *ishell.Context) { v := getVMFromContext(c) + if len(c.Args) < 1 { + c.Err(errors.New("missing parameter ")) + return + } if err := v.LoadFile(c.Args[0]); err != nil { c.Err(err) } else { @@ -253,6 +257,10 @@ func handleLoadAVM(c *ishell.Context) { func handleLoadBase64(c *ishell.Context) { v := getVMFromContext(c) + if len(c.Args) < 1 { + c.Err(errors.New("missing parameter ")) + return + } b, err := base64.StdEncoding.DecodeString(c.Args[0]) if err != nil { c.Err(err) @@ -265,6 +273,10 @@ func handleLoadBase64(c *ishell.Context) { func handleLoadHex(c *ishell.Context) { v := getVMFromContext(c) + if len(c.Args) < 1 { + c.Err(errors.New("missing parameter ")) + return + } b, err := hex.DecodeString(c.Args[0]) if err != nil { c.Err(err) @@ -277,6 +289,10 @@ func handleLoadHex(c *ishell.Context) { func handleLoadGo(c *ishell.Context) { v := getVMFromContext(c) + if len(c.Args) < 1 { + c.Err(errors.New("missing parameter ")) + return + } fb, err := ioutil.ReadFile(c.Args[0]) if err != nil { c.Err(err)