@@ -34749,6 +34749,89 @@ static int test_ed448_rejects_identity_key(void)
3474934749 return EXPECT_RESULT();
3475034750}
3475134751
34752+ /* Test: wc_PKCS7_DecodeEncryptedData must respect outputSz.
34753+ * 588-byte EncryptedData blob: 496 bytes of 'A' encrypted with
34754+ * AES-256-CBC under all-zero key/IV. Decrypted content is 496 bytes,
34755+ * but we pass a 128-byte output buffer. Must return BUFFER_E. */
34756+ static int test_pkcs7_decode_encrypted_outputsz(void)
34757+ {
34758+ EXPECT_DECLS;
34759+ #if defined(HAVE_PKCS7) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \
34760+ !defined(WOLFSSL_NO_MALLOC) && defined(WOLFSSL_AES_256)
34761+ wc_PKCS7* p7 = NULL;
34762+ byte key[32];
34763+ byte out[128]; /* smaller than 496-byte decrypted content */
34764+
34765+ static const byte encBlob[] = {
34766+ 0x30,0x82,0x02,0x48,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
34767+ 0x01,0x07,0x06,0xa0,0x82,0x02,0x39,0x30,0x82,0x02,0x35,0x02,
34768+ 0x01,0x00,0x30,0x82,0x02,0x2e,0x06,0x09,0x2a,0x86,0x48,0x86,
34769+ 0xf7,0x0d,0x01,0x07,0x01,0x30,0x1d,0x06,0x09,0x60,0x86,0x48,
34770+ 0x01,0x65,0x03,0x04,0x01,0x2a,0x04,0x10,0x00,0x00,0x00,0x00,
34771+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34772+ 0x80,0x82,0x02,0x00,0x7e,0x0e,0x75,0x77,0xef,0x9c,0x30,0xa6,
34773+ 0xbf,0x0b,0x25,0xe0,0x62,0x1e,0x82,0x7e,0x76,0xf7,0x57,0xef,
34774+ 0x12,0x71,0xc5,0x74,0x0e,0x60,0xc3,0x3c,0x8e,0xc3,0xce,0x70,
34775+ 0xbd,0x3c,0xb4,0x60,0x76,0xb1,0xea,0xb5,0x4b,0xc1,0xfe,0x5b,
34776+ 0x88,0xfa,0x43,0x46,0x03,0x28,0x9d,0xab,0x3d,0xb5,0x88,0x50,
34777+ 0x07,0xfc,0x3c,0xc9,0x49,0x4d,0x68,0x97,0xb1,0x59,0xb6,0x35,
34778+ 0xa1,0x68,0x80,0xb0,0x8f,0xb2,0x21,0x9b,0xfc,0xd8,0xf0,0x67,
34779+ 0xbc,0x4b,0x9b,0x28,0x1c,0x3b,0xa0,0x40,0x76,0x8f,0x1f,0x9f,
34780+ 0x87,0xe6,0xe4,0xa5,0xdc,0x9a,0x9a,0x84,0x86,0xff,0x43,0x8a,
34781+ 0x57,0x8d,0x97,0xd2,0x8f,0x67,0x90,0xd8,0x4f,0x0f,0x0d,0xac,
34782+ 0x56,0x6d,0x51,0x33,0xa3,0x37,0x9e,0xe9,0xbf,0x07,0xab,0x93,
34783+ 0xbc,0xbe,0xc1,0x64,0x07,0x30,0xf0,0xff,0x89,0x0a,0x36,0x1c,
34784+ 0xc8,0xe9,0xae,0x24,0x1f,0x95,0x5c,0xa1,0x8a,0x3e,0x15,0x86,
34785+ 0x49,0x70,0x55,0xc2,0xa5,0x90,0xb9,0xda,0x2b,0x97,0x6f,0x5f,
34786+ 0x60,0x61,0xc9,0xcf,0x4d,0x3a,0xb1,0xe4,0x9f,0x37,0x0f,0xf3,
34787+ 0xba,0x85,0x04,0x52,0x68,0x00,0x47,0x3d,0x83,0xc1,0x3f,0xc6,
34788+ 0x70,0x97,0xc1,0x0c,0xc0,0x0b,0xa2,0xcb,0x8c,0x88,0xb5,0x01,
34789+ 0x29,0x7f,0x7e,0xd2,0x46,0x24,0x82,0x92,0x28,0xdd,0x49,0x53,
34790+ 0x0f,0x76,0xad,0x4b,0x81,0x85,0x3a,0x9f,0xda,0x0d,0x69,0xe2,
34791+ 0x57,0xb9,0xe9,0xfa,0x53,0xed,0x20,0x6f,0x62,0x43,0x1d,0x21,
34792+ 0xa9,0x53,0x3d,0xd5,0xb9,0x1a,0x4b,0x3e,0xb7,0x05,0x87,0xb6,
34793+ 0xe3,0xfe,0x03,0x09,0xe1,0x74,0x34,0x42,0x84,0xb1,0x06,0xf9,
34794+ 0xfe,0x64,0xc1,0xd2,0xce,0x3d,0x29,0xf4,0x94,0xb8,0xfc,0xbe,
34795+ 0xb1,0x90,0xd6,0x38,0x61,0x4e,0x43,0x36,0x4e,0x27,0x87,0xd3,
34796+ 0x24,0xdc,0x34,0xf0,0x28,0x2d,0xc8,0xff,0x89,0x9f,0xeb,0xee,
34797+ 0x0d,0x45,0xfb,0xc5,0x53,0xd3,0xdf,0xcb,0xf8,0xeb,0x7e,0xcb,
34798+ 0x2a,0xd7,0xa2,0xd6,0x6a,0xf1,0xb8,0x24,0xa1,0x05,0x16,0x56,
34799+ 0x2e,0x03,0xfe,0x21,0x19,0x36,0x8a,0xeb,0x50,0x8d,0x42,0x31,
34800+ 0x1d,0xb3,0x0a,0x13,0x1d,0x16,0x09,0x0b,0x40,0x4e,0x90,0x78,
34801+ 0xbf,0x41,0x5f,0x4d,0xd9,0xce,0x91,0xaa,0xd0,0x38,0x5c,0xfb,
34802+ 0xc4,0x9f,0x55,0x4e,0x04,0x9d,0xd0,0xca,0x74,0x3c,0x6c,0x01,
34803+ 0x1b,0x84,0x76,0xfa,0xba,0x5d,0x2d,0x35,0x7e,0xe3,0x37,0x8b,
34804+ 0x72,0x0a,0xbb,0xa4,0x4d,0x56,0x2b,0x3b,0x9f,0x5a,0xa0,0xe3,
34805+ 0x60,0x26,0x65,0x09,0xed,0xfc,0x10,0x0c,0xa1,0x4f,0x12,0x76,
34806+ 0xe2,0x4c,0xbd,0x1b,0x67,0xb4,0xb4,0x54,0x5c,0x38,0x47,0x8b,
34807+ 0x7e,0x35,0x8e,0x4d,0x4e,0xef,0x91,0x3f,0xff,0x16,0x0a,0x42,
34808+ 0x0b,0xe5,0x28,0x26,0x24,0x9f,0x6f,0xb4,0x63,0x8a,0xa1,0x52,
34809+ 0x22,0x3a,0xdb,0xd9,0x8e,0x76,0x6e,0x6a,0xa9,0xa1,0xec,0xf2,
34810+ 0x9c,0x58,0xf8,0x6b,0xdd,0xf2,0xf8,0x2d,0xcb,0x8c,0x96,0xda,
34811+ 0xb4,0x9c,0x44,0xdc,0xab,0x43,0x2c,0x22,0xf3,0xfe,0x1a,0xb9,
34812+ 0x3b,0x82,0x30,0xa2,0xc7,0xef,0x52,0x08,0x7b,0x4f,0x3f,0x7a,
34813+ 0x7e,0x28,0xd7,0x67,0xb9,0xb1,0x69,0x9b,0x96,0x3e,0xc5,0xe4,
34814+ 0x45,0xb0,0x23,0x75,0x00,0xda,0xee,0xdb,0x6d,0xa9,0xe7,0x98
34815+ };
34816+
34817+ XMEMSET(key, 0, sizeof(key));
34818+
34819+ p7 = wc_PKCS7_New(NULL, INVALID_DEVID);
34820+ ExpectNotNull(p7);
34821+ if (p7 != NULL) {
34822+ p7->encryptionKey = key;
34823+ p7->encryptionKeySz = sizeof(key);
34824+
34825+ /* 496-byte content into 128-byte buffer must return BUFFER_E */
34826+ ExpectIntLT(wc_PKCS7_DecodeEncryptedData(p7, (byte*)encBlob,
34827+ (word32)sizeof(encBlob), out, sizeof(out)), 0);
34828+
34829+ wc_PKCS7_Free(p7);
34830+ }
34831+ #endif
34832+ return EXPECT_RESULT();
34833+ }
34834+
3475234835TEST_CASE testCases[] = {
3475334836 TEST_DECL(test_fileAccess),
3475434837
@@ -35564,6 +35647,7 @@ TEST_CASE testCases[] = {
3556435647 TEST_DECL(test_wc_DhSetNamedKey),
3556535648 TEST_DECL(test_DhAgree_rejects_p_minus_1),
3556635649 TEST_DECL(test_ed448_rejects_identity_key),
35650+ TEST_DECL(test_pkcs7_decode_encrypted_outputsz),
3556735651
3556835652#if defined(WOLFSSL_SNIFFER) && defined(WOLFSSL_SNIFFER_CHAIN_INPUT)
3556935653 TEST_DECL(test_sniffer_chain_input_overflow),
0 commit comments