From 32b7ccb6c9e91be56badb62c043177eb27126bad Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Wed, 14 Jun 2023 13:56:23 -0700 Subject: [PATCH] fix: x/auth/types: ensure nil .BaseAccounts are reported in ModuleAccount.Validate This change ensures that ModuleAccount.Validate flags nil .BaseAccount to avoid a nil pointer dereference. This bug was found by fuzzing cosmos/gaia. Fixes #16552 --- x/auth/types/account.go | 4 ++++ x/auth/types/account_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 9345d819d240..6a6a8cec7d8f 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -222,6 +222,10 @@ func (ma ModuleAccount) Validate() error { return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name) } + if ma.BaseAccount == nil { + return errors.New("uninitialized ModuleAccount: BaseAccount is nil") + } + return ma.BaseAccount.Validate() } diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 545e3beef5d1..d29372dcd081 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -193,3 +193,8 @@ func TestNewModuleAddressOrBech32Address(t *testing.T) { require.Equal(t, input, types.NewModuleAddressOrBech32Address(input).String()) require.Equal(t, "cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl", types.NewModuleAddressOrBech32Address("distribution").String()) } + +func TestModuleAccountValidateNilBaseAccount(t *testing.T) { + ma := &types.ModuleAccount{Name: "foo"} + _ = ma.Validate() +}