diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a113d22a7..49d310ab36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Bug Fixes * (x/auth) [#23741](https://github.com/cosmos/cosmos-sdk/pull/23741) Support legacy global AccountNumber. +* (baseapp) [#23879](https://github.com/cosmos/cosmos-sdk/pull/23879) Ensure finalize block response is not empty in the defer check of FinalizeBlock to avoid panic by nil pointer. * (types/query) [#23880](https://github.com/cosmos/cosmos-sdk/pull/23880) Fix NPE in query pagination. ### Removed diff --git a/baseapp/abci.go b/baseapp/abci.go index 3b956b4cef..1208a2d6eb 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -903,6 +903,9 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz // where they adhere to the sdk.Tx interface. func (app *BaseApp) FinalizeBlock(req *abci.FinalizeBlockRequest) (res *abci.FinalizeBlockResponse, err error) { defer func() { + if res == nil { + return + } // call the streaming service hooks with the FinalizeBlock messages for _, streamingListener := range app.streamingManager.ABCIListeners { if streamErr := streamingListener.ListenFinalizeBlock(app.finalizeBlockState.Context(), *req, *res); streamErr != nil { diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 32e3b94e3f..46f9a36adb 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -2779,3 +2779,18 @@ func TestABCI_Proposal_FailReCheckTx(t *testing.T) { require.NotEmpty(t, res.TxResults[0].Events) require.True(t, res.TxResults[0].IsOK(), fmt.Sprintf("%v", res)) } + +func TestFinalizeBlockDeferResponseHandle(t *testing.T) { + suite := NewBaseAppSuite(t, baseapp.SetHaltHeight(1)) + suite.baseApp.SetStreamingManager(storetypes.StreamingManager{ + ABCIListeners: []storetypes.ABCIListener{ + &mockABCIListener{}, + }, + }) + + res, err := suite.baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{ + Height: 2, + }) + require.Empty(t, res) + require.NotEmpty(t, err) +}