From be0609cc7a7b7fc84e3aceac714ad6dd5d95f602 Mon Sep 17 00:00:00 2001 From: Anna Shaleva <shaleva.ann@nspcc.ru> Date: Tue, 22 Dec 2020 18:21:04 +0300 Subject: [PATCH] rpc: fix `getapplicationlog` RPC handler Fixes the following panic: ``` 2020/12/22 18:16:09 http: panic serving 127.0.0.1:50228: runtime error: invalid memory address or nil pointer dereference goroutine 4043 [running]: net/http.(*conn).serve.func1(0xc00094c960) net/http/server.go:1772 +0x139 panic(0xcd9b40, 0x16a94e0) runtime/panic.go:973 +0x396 github.com/nspcc-dev/neo-go/pkg/rpc/server.(*Server).getApplicationLog(0xc000094ea0, 0xc000472d20, 0x2, 0x4, 0xc0000be228, 0xc0007ad601, 0x28) github.com/nspcc-dev/neo-go/pkg/rpc/server/server.go:542 +0xac github.com/nspcc-dev/neo-go/pkg/rpc/server.(*Server).handleIn(0xc000094ea0, 0xc000089770, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) github.com/nspcc-dev/neo-go/pkg/rpc/server/server.go:326 +0x981 github.com/nspcc-dev/neo-go/pkg/rpc/server.(*Server).handleRequest(0xc000094ea0, 0xc001bccba0, 0x0, 0x0, 0x0) github.com/nspcc-dev/neo-go/pkg/rpc/server/server.go:296 +0x26a github.com/nspcc-dev/neo-go/pkg/rpc/server.(*Server).handleHTTPRequest(0xc000094ea0, 0x1071f40, 0xc000b089a0, 0xc00053c200) github.com/nspcc-dev/neo-go/pkg/rpc/server/server.go:290 +0x91b net/http.HandlerFunc.ServeHTTP(0xc0004e61b0, 0x1071f40, 0xc000b089a0, 0xc00053c200) net/http/server.go:2012 +0x44 net/http.serverHandler.ServeHTTP(0xc0000d2ee0, 0x1071f40, 0xc000b089a0, 0xc00053c200) net/http/server.go:2807 +0xa3 net/http.(*conn).serve(0xc00094c960, 0x10749c0, 0xc0006ae980) net/http/server.go:1895 +0x86c created by net/http.(*Server).Serve net/http/server.go:2933 +0x35c ``` --- pkg/rpc/server/server.go | 6 +++++- pkg/rpc/server/server_test.go | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index f960395f9..1c6565b95 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -539,7 +539,11 @@ func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *resp trig := trigger.All if len(reqParams) > 1 { - trig, err = trigger.FromString(reqParams.ValueWithType(1, request.StringT).String()) + trigString := reqParams.ValueWithType(1, request.StringT) + if trigString == nil { + return nil, response.ErrInvalidParams + } + trig, err = trigger.FromString(trigString.String()) if err != nil { return nil, response.ErrInvalidParams } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index f1bf8384d..22c47b757 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -121,6 +121,11 @@ var rpcTestCases = map[string][]rpcTestCase{ assert.Equal(t, vm.HaltState, res.Executions[0].VMState) }, }, + { + name: "invalid trigger (not a string)", + params: `["` + genesisBlockHash + `", 1]`, + fail: true, + }, { name: "no params", params: `[]`,