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

```
This commit is contained in:
Anna Shaleva 2020-12-22 18:21:04 +03:00
parent 33386065bc
commit be0609cc7a
2 changed files with 10 additions and 1 deletions

View file

@ -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
}

View file

@ -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: `[]`,