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

fix: app: make SimGenesisAccount.Validate error if .BaseAccount is nil #2591

Closed

Conversation

odeke-em
Copy link
Contributor

@odeke-em odeke-em commented Jun 14, 2023

This change ensures that an error is returned, instead of panicking, when SimGenesisAccount.BaseAccount is nil, after invoking .Validate. Found by fuzzing and added the tests in here to catch future regressions.

Fixes #2586

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • Included the correct type prefix in the PR title
  • Targeted the correct branch (see PR Targeting)
  • Provided a link to the relevant issue or specification
  • Included the necessary unit and integration tests
  • Added a changelog entry to CHANGELOG.md
  • Included comments for documenting Go code
  • Confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed documentation is accurate
  • reviewed tests and test coverage

This change ensures that an error is returned, instead of panicking,
when SimGenesisAccount.BaseAccount is nil, after invoking .Validate.
Found by fuzzing and added the tests in here to catch future
regressions.

Fixes cosmos#2586
@odeke-em
Copy link
Contributor Author

/cc @elias-orijtech

@yaruwangway
Copy link
Contributor

Hi, it seems the test failed, due to fuzz can still assign a nil to types.Int in the coins.

runtime error: invalid memory address or nil pointer dereference

goroutine 50 [running]:
runtime/debug.Stack()
/usr/local/go/src/runtime/debug/stack.go:24 +0x64
github.com/cosmos/gaia/v11/app.TestFuzzGenesisAccountValidate.func1()
/Users/yaruwang/code/gaia/app/app_genesis_fuzz_test.go:25 +0x50
panic({0x1060318c0, 0x106e81580})
/usr/local/go/src/runtime/panic.go:884 +0x204
math/big.(*Int).Sign(...)
/usr/local/go/src/math/big/int.go:41
github.com/cosmos/cosmos-sdk/types.Int.IsZero(...)
/Users/xxx/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.16-ics/types/int.go:188
github.com/cosmos/cosmos-sdk/types.Coin.IsZero(...)
/Users/xxx/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.16-ics/types/coin.go:61
github.com/cosmos/cosmos-sdk/types.Coins.IsZero(...)
/Users/xxx/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.16-ics/types/coin.go:584
github.com/cosmos/gaia/v11/app.SimGenesisAccount.Validate({0x0, {0x14000ca62d0, 0xa, 0xa}, {0x14000ca63c0, 0xa, 0xa}, {0x140001ec540, 0x9, 0x9}, ...})
/Users/xxx/code/gaia/app/genesis_account.go:31 +0x48
github.com/cosmos/gaia/v11/app.TestFuzzGenesisAccountValidate(0x14000c996c0)
/Users/xxx/code/gaia/app/app_genesis_fuzz_test.go:34 +0x170
testing.tRunner(0x14000c996c0, 0x1062200a0)
/usr/local/go/src/testing/testing.go:1576 +0x10c
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1629 +0x368
FAIL
exit status 1

@p-offtermatt
Copy link
Contributor

Hi, thanks for your contribution, appreciate it!

I took the liberty of adding the author checklist to your pr, could you fill it out and make sure to check the boxes?

Some additional comments:

  • Could you take a look at the lint and test failures? I think the gofuzz package needs to be added to go.sum
  • Could you add a changelog entry for the fix?

Thanks again!

@mpoke
Copy link
Contributor

mpoke commented Jul 25, 2023

@odeke-em Could you please address the comments above?

@yaruwangway
Copy link
Contributor

yaruwangway commented Aug 9, 2023

Hi, I merge the commits to this PR and fix there. #2690
so close here.

@yaruwangway yaruwangway closed this Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

app: SimGenesisAccount.Validate() should firstly ensure that .BaseAccount != nil lest result in a panic
4 participants