forked from TrueCloudLab/neoneo-go
Merge pull request #1908 from nspcc-dev/codeql-fixes
rpc, internal: fix CodeQL int conversions warnings
This commit is contained in:
commit
89ba6bfc43
3 changed files with 33 additions and 0 deletions
|
@ -2,6 +2,7 @@ package fakechain
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"math/big"
|
||||
"sync/atomic"
|
||||
|
||||
|
@ -233,6 +234,9 @@ func (chain *FakeChain) GetNativeContractScriptHash(name string) (util.Uint160,
|
|||
|
||||
// GetHeaderHash implements Blockchainer interface.
|
||||
func (chain *FakeChain) GetHeaderHash(n int) util.Uint256 {
|
||||
if n < 0 || n > math.MaxUint32 {
|
||||
return util.Uint256{}
|
||||
}
|
||||
return chain.hdrHashes[uint32(n)]
|
||||
}
|
||||
|
||||
|
|
|
@ -841,6 +841,9 @@ func (s *Server) contractIDFromParam(param *request.Param) (int32, *response.Err
|
|||
if err != nil {
|
||||
return 0, response.ErrInvalidParams
|
||||
}
|
||||
if err := checkInt32(id); err != nil {
|
||||
return 0, response.WrapErrorWithData(response.ErrInvalidParams, err)
|
||||
}
|
||||
result = int32(id)
|
||||
default:
|
||||
return 0, response.ErrInvalidParams
|
||||
|
@ -874,6 +877,9 @@ func (s *Server) contractScriptHashFromParam(param *request.Param) (util.Uint160
|
|||
if err != nil {
|
||||
return result, response.ErrInvalidParams
|
||||
}
|
||||
if err := checkInt32(id); err != nil {
|
||||
return result, response.WrapErrorWithData(response.ErrInvalidParams, err)
|
||||
}
|
||||
result, err = s.chain.GetContractScriptHash(int32(id))
|
||||
if err != nil {
|
||||
return result, response.NewRPCError("Unknown contract", "", err)
|
||||
|
@ -969,6 +975,9 @@ func (s *Server) getStateRoot(ps request.Params) (interface{}, *response.Error)
|
|||
var h util.Uint256
|
||||
height, err := p.GetInt()
|
||||
if err == nil {
|
||||
if err := checkUint32(height); err != nil {
|
||||
return nil, response.WrapErrorWithData(response.ErrInvalidParams, err)
|
||||
}
|
||||
rt, err = s.chain.GetStateModule().GetStateRoot(uint32(height))
|
||||
} else if h, err = p.GetUint256(); err == nil {
|
||||
var hdr *block.Header
|
||||
|
|
20
pkg/rpc/server/util.go
Normal file
20
pkg/rpc/server/util.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
)
|
||||
|
||||
func checkUint32(i int) error {
|
||||
if i < 0 || i > math.MaxUint32 {
|
||||
return errors.New("value should fit uint32")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkInt32(i int) error {
|
||||
if i < math.MinInt32 || i > math.MaxInt32 {
|
||||
return errors.New("value should fit int32")
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue