From 554850dcc7aa961aef1cb9021b4c54385ff9a715 Mon Sep 17 00:00:00 2001 From: Evgeni Margolis Date: Sat, 11 Jun 2022 04:52:22 -0700 Subject: [PATCH] Fix Potential ASN1 Buffer Overflows in EnterContainer() and DecodeHead() --- src/lib/asn1/ASN1Reader.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/asn1/ASN1Reader.cpp b/src/lib/asn1/ASN1Reader.cpp index 9309dc53448721..1feb402f46a855 100644 --- a/src/lib/asn1/ASN1Reader.cpp +++ b/src/lib/asn1/ASN1Reader.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2021 Project CHIP Authors + * Copyright (c) 2020-2022 Project CHIP Authors * Copyright (c) 2013-2017 Nest Labs, Inc. * All rights reserved. * @@ -113,6 +113,7 @@ CHIP_ERROR ASN1Reader::EnterContainer(uint32_t offset) mElemStart = Value + offset; if (!IndefiniteLen) { + VerifyOrReturnError(mBufEnd - Value >= ValueLen, ASN1_ERROR_VALUE_OVERFLOW); mContainerEnd = Value + ValueLen; } @@ -303,8 +304,8 @@ CHIP_ERROR ASN1Reader::DecodeHead() IndefiniteLen = false; } + VerifyOrReturnError(mBufEnd - p >= ValueLen, ASN1_ERROR_VALUE_OVERFLOW); VerifyOrReturnError(CanCastTo(p - mElemStart), ASN1_ERROR_VALUE_OVERFLOW); - mHeadLen = static_cast(p - mElemStart); EndOfContents = (Class == kASN1TagClass_Universal && Tag == 0 && !Constructed && ValueLen == 0);