Skip to content

Commit

Permalink
[PacketBufferHandle::IsNull] The response PacketBufferHandle is missi…
Browse files Browse the repository at this point in the history
…ng a null check (#25520)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jul 19, 2023
1 parent 493ed1d commit b7993c4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/protocols/echo/EchoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ namespace Echo {
CHIP_ERROR EchoServer::Init(Messaging::ExchangeManager * exchangeMgr)
{
// Error if already initialized.
if (mExchangeMgr != nullptr)
return CHIP_ERROR_INCORRECT_STATE;
VerifyOrReturnError(mExchangeMgr == nullptr, CHIP_ERROR_INCORRECT_STATE);

mExchangeMgr = exchangeMgr;
OnEchoRequestReceived = nullptr;
Expand Down Expand Up @@ -63,9 +62,6 @@ CHIP_ERROR EchoServer::OnUnsolicitedMessageReceived(const PayloadHeader & payloa
CHIP_ERROR EchoServer::OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && payload)
{
CHIP_ERROR err = CHIP_NO_ERROR;
System::PacketBufferHandle response;

// NOTE: we already know this is an Echo Request message because we explicitly registered with the
// Exchange Manager for unsolicited Echo Requests.

Expand All @@ -75,6 +71,8 @@ CHIP_ERROR EchoServer::OnMessageReceived(Messaging::ExchangeContext * ec, const
OnEchoRequestReceived(ec, payload.Retain());
}

System::PacketBufferHandle response;

// Since we are re-using the inbound EchoRequest buffer to send the EchoResponse, if necessary,
// adjust the position of the payload within the buffer to ensure there is enough room for the
// outgoing network headers. This is necessary because in some network stack configurations,
Expand All @@ -86,12 +84,11 @@ CHIP_ERROR EchoServer::OnMessageReceived(Messaging::ExchangeContext * ec, const
else
{
response = MessagePacketBuffer::NewWithData(payload->Start(), payload->DataLength());
VerifyOrReturnError(!response.IsNull(), CHIP_ERROR_NO_MEMORY);
}

// Send an Echo Response back to the sender.
err = ec->SendMessage(MsgType::EchoResponse, std::move(response));

return err;
return ec->SendMessage(MsgType::EchoResponse, std::move(response));
}

} // namespace Echo
Expand Down

0 comments on commit b7993c4

Please sign in to comment.