From e489944c29890b4a10dab178b7a876321ea6ec7b Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Tue, 6 Apr 2021 14:05:46 -0700 Subject: [PATCH] Fix the missing commandList container closure in IM command (#5799) Problem: src/app/Command.h and .cpp create incomplete tlv data, the commandList array is missing the end of container byte Calling Command::Init() followed by Command::FinalizeCommandsMessage() results in following invalid tlv data: 15 36 00 18 It should be: 15 36 00 18 18 This affects every interactive model command, they are all incomplete/invalid. Summary of Changes: add this to beginning of Command::FinalizeCommandsMessage(): mInvokeCommandBuilder.GetCommandListBuilder().EndOfCommandList() fixes #5789 --- src/app/Command.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/Command.cpp b/src/app/Command.cpp index bdb554dc4cf5a7..5b6107f85c5dc9 100644 --- a/src/app/Command.cpp +++ b/src/app/Command.cpp @@ -52,7 +52,7 @@ CHIP_ERROR Command::Init(Messaging::ExchangeManager * apExchangeMgr, Interaction CHIP_ERROR Command::Reset() { CHIP_ERROR err = CHIP_NO_ERROR; - + CommandList::Builder commandListBuilder; ClearExistingExchangeContext(); if (mCommandMessageBuf.IsNull()) @@ -66,7 +66,8 @@ CHIP_ERROR Command::Reset() err = mInvokeCommandBuilder.Init(&mCommandMessageWriter); SuccessOrExit(err); - mInvokeCommandBuilder.CreateCommandListBuilder(); + commandListBuilder = mInvokeCommandBuilder.CreateCommandListBuilder(); + SuccessOrExit(commandListBuilder.GetError()); MoveToState(CommandState::Initialized); mCommandIndex = 0; @@ -265,6 +266,9 @@ CHIP_ERROR Command::FinalizeCommandsMessage() { CHIP_ERROR err = CHIP_NO_ERROR; + CommandList::Builder commandListBuilder = mInvokeCommandBuilder.GetCommandListBuilder().EndOfCommandList(); + SuccessOrExit(commandListBuilder.GetError()); + mInvokeCommandBuilder.EndOfInvokeCommand(); err = mInvokeCommandBuilder.GetError(); SuccessOrExit(err);