From c60104f7f2cd6d68d4724abac2c25e3b5c2a36ed Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 7 Aug 2022 14:00:44 +0200 Subject: [PATCH] fix: ics27 check packet data length explicitly over nil check (#1882) (#1897) * using len check in favour of nil check for interchain account packet data * adding changelog * updating changelog (cherry picked from commit 73fdde9968200edcf00fe72d419e003f262b3275) Co-authored-by: Damian Nolan --- CHANGELOG.md | 2 ++ modules/apps/27-interchain-accounts/types/packet.go | 2 +- modules/apps/27-interchain-accounts/types/packet_test.go | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a11a862f04..90d44e9c891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking +* (apps/27-interchain-accounts) [\#1882](https://github.com/cosmos/ibc-go/pull/1882) Explicitly check length of interchain account packet data in favour of nil check. + ### Improvements * (core/02-client) [\#1570](https://github.com/cosmos/ibc-go/pull/1570) Emitting an event when handling an upgrade client proposal. diff --git a/modules/apps/27-interchain-accounts/types/packet.go b/modules/apps/27-interchain-accounts/types/packet.go index e7669a77fc9..59419f8f302 100644 --- a/modules/apps/27-interchain-accounts/types/packet.go +++ b/modules/apps/27-interchain-accounts/types/packet.go @@ -16,7 +16,7 @@ func (iapd InterchainAccountPacketData) ValidateBasic() error { return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data type cannot be unspecified") } - if iapd.Data == nil { + if len(iapd.Data) == 0 { return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty") } diff --git a/modules/apps/27-interchain-accounts/types/packet_test.go b/modules/apps/27-interchain-accounts/types/packet_test.go index 840ca529851..59bf63ea9a9 100644 --- a/modules/apps/27-interchain-accounts/types/packet_test.go +++ b/modules/apps/27-interchain-accounts/types/packet_test.go @@ -40,6 +40,15 @@ func (suite *TypesTestSuite) TestValidateBasic() { }, { "empty data", + types.InterchainAccountPacketData{ + Type: types.EXECUTE_TX, + Data: []byte{}, + Memo: "memo", + }, + false, + }, + { + "nil data", types.InterchainAccountPacketData{ Type: types.EXECUTE_TX, Data: nil,