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

Handle an (invalid) empty WriteResponses list. #25229

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/controller/WriteInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class WriteCallback final : public app::WriteClient::Callback
using OnErrorCallbackType = std::function<void(const app::ConcreteAttributePath * path, CHIP_ERROR err)>;
using OnDoneCallbackType = std::function<void(app::WriteClient *)>;

WriteCallback(OnSuccessCallbackType aOnSuccess, OnErrorCallbackType aOnError, OnDoneCallbackType aOnDone) :
mOnSuccess(aOnSuccess), mOnError(aOnError), mOnDone(aOnDone), mCallback(this)
WriteCallback(OnSuccessCallbackType aOnSuccess, OnErrorCallbackType aOnError, OnDoneCallbackType aOnDone, bool aIsGroupWrite) :
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
mOnSuccess(aOnSuccess), mOnError(aOnError), mOnDone(aOnDone), mIsGroupWrite(aIsGroupWrite), mCallback(this)
{}

app::WriteClient::Callback * GetChunkedCallback() { return &mCallback; }
Expand Down Expand Up @@ -88,6 +88,16 @@ class WriteCallback final : public app::WriteClient::Callback

void OnDone(app::WriteClient * apWriteClient) override
{
if (!mIsGroupWrite && !mCalledCallback)
{
// This can happen if the server sends a response with an empty
// WriteResponses list. Since we are not sending wildcard write
// paths, that's not a valid response and we should treat it as an
// error. Use the error we would have gotten if we in fact expected
// a nonempty list.
OnError(apWriteClient, CHIP_END_OF_TLV);
}

if (mOnDone != nullptr)
{
mOnDone(apWriteClient);
Expand All @@ -104,6 +114,7 @@ class WriteCallback final : public app::WriteClient::Callback
OnDoneCallbackType mOnDone = nullptr;

bool mCalledCallback = false;
bool mIsGroupWrite = false;

app::ChunkedWriteCallback mCallback;
};
Expand All @@ -121,7 +132,7 @@ CHIP_ERROR WriteAttribute(const SessionHandle & sessionHandle, chip::EndpointId
WriteCallback::OnDoneCallbackType onDoneCb = nullptr,
const Optional<DataVersion> & aDataVersion = NullOptional)
{
auto callback = Platform::MakeUnique<WriteCallback>(onSuccessCb, onErrorCb, onDoneCb);
auto callback = Platform::MakeUnique<WriteCallback>(onSuccessCb, onErrorCb, onDoneCb, sessionHandle->IsGroupSession());
VerifyOrReturnError(callback != nullptr, CHIP_ERROR_NO_MEMORY);

auto client = Platform::MakeUnique<app::WriteClient>(app::InteractionModelEngine::GetInstance()->GetExchangeManager(),
Expand Down