Skip to content

Commit

Permalink
Fix CertificationElementsDecoder::FindAndEnterArray
Browse files Browse the repository at this point in the history
This code was not handling CHIP_ERROR_WRONG_TLV_TYPE correctly. Split into
separate Next() and Expect() calls to simplify the logic.
  • Loading branch information
ksperling-apple committed Nov 2, 2023
1 parent 3c0f5c3 commit 70c709a
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/credentials/CertificationDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,10 @@ CHIP_ERROR CertificationElementsDecoder::FindAndEnterArray(const ByteSpan & enco
ReturnErrorOnFailure(mReader.EnterContainer(outerContainerType1));

// position to arrayTag Array
CHIP_ERROR error = CHIP_NO_ERROR;
do
{
error = mReader.Next(kTLVType_Array, arrayTag);
// Return error code unless one of three things happened:
// 1. We found the right thing (CHIP_NO_ERROR returned).
// 2. The next tag is not the one we are looking for (CHIP_ERROR_UNEXPECTED_TLV_ELEMENT).
VerifyOrReturnError(error == CHIP_NO_ERROR || error == CHIP_ERROR_UNEXPECTED_TLV_ELEMENT, error);
} while (error != CHIP_NO_ERROR);
ReturnErrorOnFailure(mReader.Next());
} while (mReader.Expect(kTLVType_Array, arrayTag) != CHIP_NO_ERROR);

ReturnErrorOnFailure(mReader.EnterContainer(outerContainerType2));

Expand Down

0 comments on commit 70c709a

Please sign in to comment.