From c27d5f57c494575dcd717c110e2abe04033eb27f Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Fri, 23 Oct 2020 09:44:08 -0700 Subject: [PATCH] check PKCS7 content length is not larger than bundle if not using separate header/footer --- wolfcrypt/src/pkcs7.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index e9ae9c64e..2e8020f58 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -4397,6 +4397,16 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf, /* support using header and footer without content */ if (pkiMsg2 && pkiMsg2Sz > 0 && hashBuf && hashSz > 0) { localIdx = 0; + + } else if (pkiMsg2 == NULL && hashBuf == NULL) { + /* header/footer not separate, check content length is + * not larger than total bundle size */ + if ((localIdx + length) > pkiMsgSz) { + WOLFSSL_MSG("Content length detected is larger than " + "total bundle size"); + ret = BUFFER_E; + break; + } } idx = localIdx; }