Skip to content

Commit 6722de5

Browse files
Merge pull request #10882 from kareem-wolfssl/zd22127
Use safe sum in PKCS7_VerifySignedData.
2 parents 7b50124 + f8d5905 commit 6722de5

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

wolfcrypt/src/pkcs7.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7641,9 +7641,13 @@ static int PKCS7_VerifySignedData(wc_PKCS7* pkcs7, const byte* hashBuf,
76417641

76427642
WOLFSSL_MSG("certificate set found");
76437643

7644-
/* adjust cert length */
7645-
length += (int)(localIdx - certIdx);
7646-
idx = certIdx;
7644+
if (!WC_SAFE_SUM_SIGNED(int, length,
7645+
(int)(localIdx - certIdx), length)) {
7646+
ret = ASN_PARSE_E;
7647+
}
7648+
else {
7649+
idx = certIdx;
7650+
}
76477651
}
76487652
}
76497653
/* in case certificates set has definite length */
@@ -7756,7 +7760,11 @@ static int PKCS7_VerifySignedData(wc_PKCS7* pkcs7, const byte* hashBuf,
77567760
ret = ASN_PARSE_E;
77577761

77587762
cert = &pkiMsg2[idx];
7759-
certSz += (int)(certIdx - idx);
7763+
if (!WC_SAFE_SUM_SIGNED(int, certSz,
7764+
(int)(certIdx - idx), certSz)) {
7765+
ret = BUFFER_E;
7766+
break;
7767+
}
77607768
if (certSz > length) {
77617769
ret = BUFFER_E;
77627770
break;

0 commit comments

Comments
 (0)