Skip to content

Commit 7a5e97e

Browse files
adjustment for recipient index advancement
1 parent 6987304 commit 7a5e97e

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

wolfcrypt/src/pkcs7.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12316,9 +12316,17 @@ static int wc_PKCS7_ParseToRecipientInfoSet(wc_PKCS7* pkcs7, byte* in,
1231612316

1231712317
#ifndef NO_PKCS7_STREAM
1231812318
pkcs7->stream->expected = (word32)length;
12319+
1231912320
if ((ret = wc_PKCS7_StreamEndCase(pkcs7, &tmpIdx, idx)) != 0) {
1232012321
break;
1232112322
}
12323+
12324+
/* update the stored max length */
12325+
if (pkcs7->stream->totalRd + pkcs7->stream->expected >
12326+
pkcs7->stream->maxLen) {
12327+
pkcs7->stream->maxLen = pkcs7->stream->totalRd +
12328+
pkcs7->stream->expected;
12329+
}
1232212330
#endif
1232312331

1232412332
if (ret == 0)
@@ -12461,7 +12469,8 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1246112469
#ifndef NO_PKCS7_STREAM
1246212470
tmpIdx = idx;
1246312471
pkcs7->stream->aad = decryptedKey;
12464-
pkcs7->stream->expected = (word32)ret; /* get the full recipient set */
12472+
/* get the full recipient set */
12473+
pkcs7->stream->expected = (word32)ret;
1246512474
pkcs7->stream->recipientSz = ret;
1246612475
#endif
1246712476
FALL_THROUGH;
@@ -12488,6 +12497,7 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1248812497
decryptedKeySz = MAX_ENCRYPTED_KEY_SZ;
1248912498
tmpIdx = idx;
1249012499
#endif
12500+
pkiMsgSz = (pkcs7->stream->length > 0)? pkcs7->stream->length: inSz;
1249112501

1249212502
ret = wc_PKCS7_DecryptRecipientInfos(pkcs7, in, inSz, &idx,
1249312503
decryptedKey, &decryptedKeySz,
@@ -12501,12 +12511,16 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1250112511
if (ret != 0)
1250212512
break;
1250312513
#ifndef NO_PKCS7_STREAM
12504-
/* advance idx past recipient info set */
12505-
idx = tmpIdx + (word32)pkcs7->stream->recipientSz;
12514+
/* advance idx past recipient info set if not all recipients
12515+
* parsed */
12516+
if (pkcs7->stream->totalRd < (pkcs7->stream->recipientSz +
12517+
tmpIdx)) {
12518+
idx = tmpIdx + (word32)pkcs7->stream->recipientSz;
1250612519

12507-
/* process aditional recipients as read */
12508-
if ((ret = wc_PKCS7_StreamEndCase(pkcs7, &tmpIdx, &idx)) != 0) {
12509-
break;
12520+
/* process additional recipients as read */
12521+
if ((ret = wc_PKCS7_StreamEndCase(pkcs7, &tmpIdx, &idx)) != 0) {
12522+
break;
12523+
}
1251012524
}
1251112525

1251212526
tmpIdx = idx;

0 commit comments

Comments
 (0)