Skip to content

Commit d0a0c32

Browse files
Prevent cert chain count from exceeding array max size when calling WriteCSRToBuffer.
Thanks to Zou Dikai for the report.
1 parent 36931c8 commit d0a0c32

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/tls13.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8882,7 +8882,7 @@ static word32 NextCert(byte* data, word32 length, word32* idx)
88828882
* extIdx The index number of certificate status request data
88838883
* for the certificate.
88848884
* offset index offset
8885-
* returns Total number of bytes written.
8885+
* returns Total number of bytes written on success or negative value on error.
88868886
*/
88878887
static int WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,
88888888
word16* extSz, word16 extSz_num)
@@ -8897,6 +8897,9 @@ static int WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,
88978897
word32 extIdx;
88988898
DerBuffer* der;
88998899

8900+
if (extSz_num > MAX_CERT_EXTENSIONS)
8901+
return BAD_FUNC_ARG;
8902+
89008903
ext = TLSX_Find(ssl->extensions, TLSX_STATUS_REQUEST);
89018904
csr = ext ? (CertificateStatusRequest*)ext->data : NULL;
89028905

@@ -9148,8 +9151,11 @@ static int SendTls13Certificate(WOLFSSL* ssl)
91489151
if (ret != 0)
91499152
return ret;
91509153

9151-
ret = WriteCSRToBuffer(ssl, &ssl->buffers.certExts[0], &extSz[0],
9152-
1 /* +1 for leaf */ + (word16)ssl->buffers.certChainCnt);
9154+
if ((word16)(1 + ssl->buffers.certChainCnt) > MAX_CERT_EXTENSIONS)
9155+
ret = BAD_FUNC_ARG;
9156+
if (ret == 0)
9157+
ret = WriteCSRToBuffer(ssl, &ssl->buffers.certExts[0], &extSz[0],
9158+
1 /* +1 for leaf */ + (word16)ssl->buffers.certChainCnt);
91539159
if (ret < 0)
91549160
return ret;
91559161
totalextSz += ret;

0 commit comments

Comments
 (0)