Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: add switch case to detect blank pointers in keeper #2393

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (light-clients/solomachine) [#1839](https://github.com/cosmos/ibc-go/issues/1839) Fixed usage of the new diversifier in validation of changing diversifiers for the solo machine. The current diversifier must sign over the new diversifier.
* (light-clients/07-tendermint) [\#1674](https://github.com/cosmos/ibc-go/pull/1674) Submitted ClientState is zeroed out before checking the proof in order to prevent the proposal from containing information governance is not actually voting on.
* (modules/core/02-client)[\#1676](https://github.com/cosmos/ibc-go/pull/1676) ClientState must be zeroed out for `UpgradeProposals` to pass validation. This prevents a proposal containing information governance is not actually voting on.
* (modules/core/keeper) [\#2268](https://github.com/cosmos/ibc-go/pull/2393) Added switch case in NewKeeper to cater for blank pointers.

## [v4.1.0](https://github.com/cosmos/ibc-go/releases/tag/v4.1.0) - 2022-09-20

Expand Down
24 changes: 20 additions & 4 deletions modules/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,28 @@ func NewKeeper(
}

// panic if any of the keepers passed in is empty
if reflect.ValueOf(stakingKeeper).IsZero() {
panic(fmt.Errorf("cannot initialize IBC keeper: empty staking keeper"))

// switch case to detect blank pointers
switch reflect.TypeOf(stakingKeeper).Kind() {
case reflect.Ptr:
if reflect.ValueOf(&stakingKeeper).IsZero() {
panic(fmt.Errorf("cannot initialize IBC keeper: empty staking keeper"))
}
default:
if reflect.ValueOf(stakingKeeper).IsZero() {
panic(fmt.Errorf("cannot initialize IBC keeper: empty staking keeper"))
}
}

if reflect.ValueOf(upgradeKeeper).IsZero() {
panic(fmt.Errorf("cannot initialize IBC keeper: empty upgrade keeper"))
switch reflect.TypeOf(upgradeKeeper).Kind() {
case reflect.Ptr:
if reflect.ValueOf(&upgradeKeeper).IsZero() {
panic(fmt.Errorf("cannot initialize IBC keeper: empty upgrade keeper"))
}
default:
if reflect.ValueOf(upgradeKeeper).IsZero() {
panic(fmt.Errorf("cannot initialize IBC keeper: empty upgrade keeper"))
}
}

if reflect.DeepEqual(capabilitykeeper.ScopedKeeper{}, scopedKeeper) {
Expand Down