Browse Source

Hotfix/validating query result length (#3053)

* Validating that there are txs in the query results before loop throught the array

* Created tests to validate the error has been fixed

* Added comments

* Fixing misspeling

* check if the variable "skipCount" is bigger than zero. If it is not, we set it to 0. If it, we do not do anything.

* using function that validates the skipCount variable

* undo Gopkg.lock changes
breaking
Gian Felipe 5 years ago
committed by Ethan Buchman
parent
commit
be00cd1add
4 changed files with 18 additions and 1 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +5
    -0
      rpc/client/rpc_test.go
  3. +9
    -0
      rpc/core/pipe.go
  4. +2
    -1
      rpc/core/tx.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -33,6 +33,8 @@ Special thanks to external contributors on this release:
- [rpc] \#3047 Include peer's remote IP in `/net_info`
### BUG FIXES:
- [types] \#2926 do not panic if retrieving the private validator's public key fails
- [rpc] \#3080 check if the variable "skipCount" is bigger than zero. If it is not, we set it to 0. If it, we do not do anything.
- [crypto/multisig] \#3102 fix multisig keys address length
- [crypto/encoding] \#3101 Fix `PubKeyMultisigThreshold` unmarshalling into `crypto.PubKey` interface

+ 5
- 0
rpc/client/rpc_test.go View File

@ -428,5 +428,10 @@ func TestTxSearch(t *testing.T) {
if len(result.Txs) == 0 {
t.Fatal("expected a lot of transactions")
}
// query a non existing tx with page 1 and txsPerPage 1
result, err = c.TxSearch("app.creator='Cosmoshi Neetowoko'", true, 1, 1)
require.Nil(t, err, "%+v", err)
require.Len(t, result.Txs, 0)
}
}

+ 9
- 0
rpc/core/pipe.go View File

@ -154,3 +154,12 @@ func validatePerPage(perPage int) int {
}
return perPage
}
func validateSkipCount(page, perPage int) int {
skipCount := (page - 1) * perPage
if skipCount < 0 {
return 0
}
return skipCount
}

+ 2
- 1
rpc/core/tx.go View File

@ -201,10 +201,11 @@ func TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSear
totalCount := len(results)
perPage = validatePerPage(perPage)
page = validatePage(page, perPage, totalCount)
skipCount := (page - 1) * perPage
skipCount := validateSkipCount(page, perPage)
apiResults := make([]*ctypes.ResultTx, cmn.MinInt(perPage, totalCount-skipCount))
var proof types.TxProof
// if there's no tx in the results array, we don't need to loop through the apiResults array
for i := 0; i < len(apiResults); i++ {
r := results[skipCount+i]
height := r.Height


Loading…
Cancel
Save