Skip to content

Commit

Permalink
Fix race condition during CRMP sendMessage (#6441)
Browse files Browse the repository at this point in the history
* Add the outgoing message to retransTable before sending

* Enable Echo and InteractionModel test in cirque

* Remove temporary encryptedMsg varible

Force-squashed because Integration tests seem to not complete.
  • Loading branch information
yufengwangca authored May 6, 2021
1 parent 587b490 commit 3c4d1a5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 2 additions & 0 deletions scripts/tests/cirque_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ OT_SIMULATION_CACHE="$CIRQUE_CACHE_PATH/ot-simulation.tgz"

# Append test name here to add more tests for run_all_tests
CIRQUE_TESTS=(
"EchoTest"
"MobileDeviceTest"
"InteractionModel"
)

BOLD_GREEN_TEXT="\033[1;32m"
Expand Down
13 changes: 1 addition & 12 deletions src/transport/SecureSessionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,7 @@ CHIP_ERROR SecureSessionMgr::SendMessage(SecureSessionHandle session, PayloadHea

Transport::AdminPairingInfo * admin = nullptr;

// Hold the reference to encrypted message in stack variable.
// In case of any failures, the reference is not returned, and this stack variable
// will automatically free the reference on returning from the function.
EncryptedPacketBufferHandle encryptedMsg;

VerifyOrExit(mState == State::kInitialized, err = CHIP_ERROR_INCORRECT_STATE);

VerifyOrExit(!msgBuf.IsNull(), err = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(!msgBuf->HasChainedBuffer(), err = CHIP_ERROR_INVALID_MESSAGE_LENGTH);

Expand Down Expand Up @@ -188,7 +182,7 @@ CHIP_ERROR SecureSessionMgr::SendMessage(SecureSessionHandle session, PayloadHea
// Retain the packet buffer in case it's needed for retransmissions.
if (bufferRetainSlot != nullptr)
{
encryptedMsg = msgBuf.Retain();
(*bufferRetainSlot) = msgBuf.Retain();
}

ChipLogProgress(Inet,
Expand All @@ -210,11 +204,6 @@ CHIP_ERROR SecureSessionMgr::SendMessage(SecureSessionHandle session, PayloadHea
ChipLogProgress(Inet, "Secure msg send status %s", ErrorStr(err));
SuccessOrExit(err);

if (bufferRetainSlot != nullptr)
{
(*bufferRetainSlot) = std::move(encryptedMsg);
}

exit:
if (!msgBuf.IsNull())
{
Expand Down

0 comments on commit 3c4d1a5

Please sign in to comment.