From d96bd30398ceb966f306b2ff0891d7ce48f4225a Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 22 Apr 2022 15:28:03 -0600 Subject: [PATCH] fix for sanity check on PKCS7 indef read --- wolfcrypt/src/pkcs7.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index 82c12c30d..0d4894c0c 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -4590,8 +4590,13 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf, ret = ASN_PARSE_E; } /* if indef, skip EOF */ - if (isIndef && pkiMsg[idx] == ASN_EOC && pkiMsg[idx+1] == 0) { - idx += 2; /* skip EOF + zero byte */ + if (isIndef) { + if (idx + 1 >= pkiMsgSz) { + ret = ASN_PARSE_E; + } + else if (pkiMsg[idx] == ASN_EOC && pkiMsg[idx+1] == 0) { + idx += 2; /* skip EOF + zero byte */ + } } }