Browse Source

light: avoid panic for integer underflow (#7589)

pull/7598/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
159d763422
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 13 deletions
  1. +1
    -3
      light/proxy/routes.go
  2. +7
    -10
      light/rpc/client.go

+ 1
- 3
light/proxy/routes.go View File

@ -16,9 +16,7 @@ type proxyService struct {
*lrpc.Client
}
func (p proxyService) ABCIQuery(ctx context.Context, path string, data tmbytes.HexBytes,
height int64, prove bool) (*coretypes.ResultABCIQuery, error) {
func (p proxyService) ABCIQuery(ctx context.Context, path string, data tmbytes.HexBytes, height int64, prove bool) (*coretypes.ResultABCIQuery, error) {
return p.ABCIQueryWithOptions(ctx, path, data, rpcclient.ABCIQueryOptions{
Height: height,
Prove: prove,


+ 7
- 10
light/rpc/client.go View File

@ -565,7 +565,7 @@ func (c *Client) Validators(
}
skipCount := validateSkipCount(page, perPage)
v := l.ValidatorSet.Validators[skipCount : skipCount+tmmath.MinInt(perPage, totalCount-skipCount)]
v := l.ValidatorSet.Validators[skipCount : skipCount+tmmath.MinInt(int(perPage), totalCount-skipCount)]
return &coretypes.ResultValidators{
BlockHeight: l.Height,
@ -672,16 +672,13 @@ const (
maxPerPage = 100
)
func validatePage(pagePtr *int, perPage, totalCount int) (int, error) {
if perPage < 1 {
panic(fmt.Errorf("%w (%d)", coretypes.ErrZeroOrNegativePerPage, perPage))
}
func validatePage(pagePtr *int, perPage uint, totalCount int) (int, error) {
if pagePtr == nil { // no page parameter
return 1, nil
}
pages := ((totalCount - 1) / perPage) + 1
pages := ((totalCount - 1) / int(perPage)) + 1
if pages == 0 {
pages = 1 // one page (even if it's empty)
}
@ -693,7 +690,7 @@ func validatePage(pagePtr *int, perPage, totalCount int) (int, error) {
return page, nil
}
func validatePerPage(perPagePtr *int) int {
func validatePerPage(perPagePtr *int) uint {
if perPagePtr == nil { // no per_page parameter
return defaultPerPage
}
@ -704,11 +701,11 @@ func validatePerPage(perPagePtr *int) int {
} else if perPage > maxPerPage {
return maxPerPage
}
return perPage
return uint(perPage)
}
func validateSkipCount(page, perPage int) int {
skipCount := (page - 1) * perPage
func validateSkipCount(page int, perPage uint) int {
skipCount := (page - 1) * int(perPage)
if skipCount < 0 {
return 0
}


Loading…
Cancel
Save