Skip to content

Commit d5af526

Browse files
committed
add length check in PKCS#7
1 parent 2d93e1c commit d5af526

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

wolfcrypt/src/pkcs7.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14444,7 +14444,16 @@ int wc_PKCS7_DecodeAuthEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1444414444
if (GetLength_ex(pkiMsg, &idx, &length, pkiMsgSz, 0) <= 0) {
1444514445
ret = ASN_PARSE_E;
1444614446
}
14447-
#ifndef NO_PKCS7_STREAM
14447+
14448+
#ifdef NO_PKCS7_STREAM
14449+
/* In non-streaming mode, validate authenticatedAttributes
14450+
* length is within the input buffer. The streaming path
14451+
* handles this via wc_PKCS7_AddDataToStream instead. */
14452+
if (ret == 0 &&
14453+
(idx > pkiMsgSz || (word32)length > pkiMsgSz - idx)) {
14454+
ret = ASN_PARSE_E;
14455+
}
14456+
#else
1444814457
pkcs7->stream->expected = (word32)length;
1444914458
#endif
1445014459
encodedAttribSz = (word32)length + (idx - encodedAttribIdx);

0 commit comments

Comments
 (0)