Skip to content

Commit e2167e4

Browse files
committed
add length check in PKCS#7
1 parent 84fb0f6 commit e2167e4

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
@@ -14455,7 +14455,16 @@ int wc_PKCS7_DecodeAuthEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1445514455
if (GetLength_ex(pkiMsg, &idx, &length, pkiMsgSz, 0) <= 0) {
1445614456
ret = ASN_PARSE_E;
1445714457
}
14458-
#ifndef NO_PKCS7_STREAM
14458+
14459+
#ifdef NO_PKCS7_STREAM
14460+
/* In non-streaming mode, validate authenticatedAttributes
14461+
* length is within the input buffer. The streaming path
14462+
* handles this via wc_PKCS7_AddDataToStream instead. */
14463+
if (ret == 0 &&
14464+
(idx > pkiMsgSz || (word32)length > pkiMsgSz - idx)) {
14465+
ret = ASN_PARSE_E;
14466+
}
14467+
#else
1445914468
pkcs7->stream->expected = (word32)length;
1446014469
#endif
1446114470
encodedAttribSz = (word32)length + (idx - encodedAttribIdx);

0 commit comments

Comments
 (0)