Skip to content

Commit

Permalink
Merge PR #5620: Fix nil pointer deref in distribution tax/rewward val…
Browse files Browse the repository at this point in the history
…idation helpers
  • Loading branch information
Alessio Treglia authored and alexanderbez committed Mar 24, 2020
1 parent de72070 commit 72c8a04
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (client) [\#5618](https://github.com/cosmos/cosmos-sdk/pull/5618) Fix crash on the client when the verifier is not set.
* (crypto/keys/mintkey) [\#5823](https://github.com/cosmos/cosmos-sdk/pull/5823) fix errors handling in UnarmorPubKeyBytes (underlying armoring function's return error was not being checked).
* (x/distribution) [\#5620](https://github.com/cosmos/cosmos-sdk/pull/5620) Fix nil pointer deref in distribution tax/rewward validation helpers.

### Improvements

Expand Down
9 changes: 9 additions & 0 deletions x/distribution/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func validateCommunityTax(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("community tax must be not nil")
}
if v.IsNegative() {
return fmt.Errorf("community tax must be positive: %s", v)
}
Expand All @@ -108,6 +111,9 @@ func validateBaseProposerReward(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("base proposer reward must be not nil")
}
if v.IsNegative() {
return fmt.Errorf("base proposer reward must be positive: %s", v)
}
Expand All @@ -124,6 +130,9 @@ func validateBonusProposerReward(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("bonus proposer reward must be not nil")
}
if v.IsNegative() {
return fmt.Errorf("bonus proposer reward must be positive: %s", v)
}
Expand Down
34 changes: 34 additions & 0 deletions x/distribution/types/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package types

import (
"testing"

"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func Test_validateAuxFuncs(t *testing.T) {
type args struct {
i interface{}
}
tests := []struct {
name string
args args
wantErr bool
}{
{"wrong type", args{10.5}, true},
{"nil Int pointer", args{sdk.Dec{}}, true},
{"negative", args{sdk.NewDec(-1)}, true},
{"one dec", args{sdk.NewDec(1)}, false},
{"two dec", args{sdk.NewDec(2)}, true},
}
for _, tt := range tests {
tt = tt
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.wantErr, validateCommunityTax(tt.args.i) != nil)
require.Equal(t, tt.wantErr, validateBaseProposerReward(tt.args.i) != nil)
require.Equal(t, tt.wantErr, validateBonusProposerReward(tt.args.i) != nil)
})
}
}

0 comments on commit 72c8a04

Please sign in to comment.