Skip to content

Commit

Permalink
Fix length in DefaultICDStorage (project-chip#30767)
Browse files Browse the repository at this point in the history
Add VerifyEndOfContainer for DefaultICDClientStorage::Load and
DefaultICDClientStorage::LoadCounter, existing test would fail,
the fix is to set right length for TLV::ScopedBufferTLVReader
  • Loading branch information
yunhanw-google authored Dec 1, 2023
1 parent 516f918 commit 2a4a2ca
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/app/icd/client/DefaultICDClientStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ CHIP_ERROR DefaultICDClientStorage::LoadCounter(FabricIndex fabricIndex, size_t
}
ReturnErrorOnFailure(err);

TLV::ScopedBufferTLVReader reader(std::move(backingBuffer), len);
TLV::ScopedBufferTLVReader reader(std::move(backingBuffer), length);
ReturnErrorOnFailure(reader.Next(TLV::kTLVType_Structure, TLV::AnonymousTag()));
TLV::TLVType structType;
ReturnErrorOnFailure(reader.EnterContainer(structType));
Expand All @@ -203,7 +203,7 @@ CHIP_ERROR DefaultICDClientStorage::LoadCounter(FabricIndex fabricIndex, size_t
clientInfoSize = static_cast<size_t>(tempClientInfoSize);

ReturnErrorOnFailure(reader.ExitContainer(structType));
return CHIP_NO_ERROR;
return reader.VerifyEndOfContainer();
}

CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector<ICDClientInfo> & clientInfoVector,
Expand All @@ -224,7 +224,7 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector<IC
}
ReturnErrorOnFailure(err);

TLV::ScopedBufferTLVReader reader(std::move(backingBuffer), len);
TLV::ScopedBufferTLVReader reader(std::move(backingBuffer), length);

ReturnErrorOnFailure(reader.Next(TLV::kTLVType_Array, TLV::AnonymousTag()));
TLV::TLVType arrayType;
Expand Down Expand Up @@ -273,7 +273,8 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector<IC
return err;
}

return reader.ExitContainer(arrayType);
ReturnErrorOnFailure(reader.ExitContainer(arrayType));
return reader.VerifyEndOfContainer();
}

CHIP_ERROR DefaultICDClientStorage::SetKey(ICDClientInfo & clientInfo, const ByteSpan keyData)
Expand Down

0 comments on commit 2a4a2ca

Please sign in to comment.