Skip to content

Commit

Permalink
Added buffer overflow check to ASN1Writer method. (#8287)
Browse files Browse the repository at this point in the history
  • Loading branch information
emargolis authored and pull[bot] committed Jul 21, 2021
1 parent 8819efd commit 3083073
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/credentials/GenerateChipX509Cert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ CHIP_ERROR EncodeChipECDSASignature(Crypto::P256ECDSASignature & signature, ASN1
{
CHIP_ERROR err = CHIP_NO_ERROR;

ASN1_START_BIT_STRING_ENCAPSULATED { writer.PutConstructedType(signature, (uint16_t) signature.Length()); }
ASN1_START_BIT_STRING_ENCAPSULATED
{
ReturnErrorOnFailure(writer.PutConstructedType(signature, (uint16_t) signature.Length()));
}
ASN1_END_ENCAPSULATED;

exit:
Expand Down
2 changes: 2 additions & 0 deletions src/lib/asn1/ASN1Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ CHIP_ERROR ASN1Writer::PutConstructedType(const uint8_t * val, uint16_t valLen)
// Do nothing for a null writer.
VerifyOrReturnError(mBuf != nullptr, CHIP_NO_ERROR);

VerifyOrReturnError((mWritePoint + valLen) <= mBufEnd, ASN1_ERROR_OVERFLOW);

memcpy(mWritePoint, val, valLen);
mWritePoint += valLen;

Expand Down

0 comments on commit 3083073

Please sign in to comment.