@@ -1603,6 +1603,34 @@ int test_DecodeCertExtensions_empty_certpol(void)
16031603 return EXPECT_RESULT ();
16041604}
16051605
1606+ /* Trailing bytes after the last PolicyInformation must be rejected rather than
1607+ * skipped. */
1608+ int test_DecodeCertExtensions_certpol_trailing_junk (void )
1609+ {
1610+ EXPECT_DECLS ;
1611+ #if (defined(WOLFSSL_SEP ) || defined(WOLFSSL_CERT_EXT )) && \
1612+ !defined(NO_CERTS ) && !defined(NO_ASN )
1613+ /* One valid PolicyInformation followed by two bytes that are not one. */
1614+ static const byte trailingJunk [] = {
1615+ 0x30 , 0x09 , /* certificatePolicies SEQUENCE */
1616+ 0x30 , 0x05 , /* PolicyInformation SEQUENCE */
1617+ 0x06 , 0x03 , 0x2A , 0x03 , 0x04 ,/* policyIdentifier OID 1.2.3.4 */
1618+ 0x00 , 0x00 /* trailing junk */
1619+ };
1620+ DecodedCert cert ;
1621+ int isUnknown = 0 ;
1622+
1623+ wc_InitDecodedCert (& cert , trailingJunk , (word32 )sizeof (trailingJunk ), NULL );
1624+
1625+ ExpectIntEQ (DecodeExtensionType (trailingJunk , (word32 )sizeof (trailingJunk ),
1626+ CERT_POLICY_OID , 0 , & cert , & isUnknown ),
1627+ WC_NO_ERR_TRACE (ASN_PARSE_E ));
1628+
1629+ wc_FreeDecodedCert (& cert );
1630+ #endif
1631+ return EXPECT_RESULT ();
1632+ }
1633+
16061634int test_ParseCert_SM3wSM2_short_pubkey (void )
16071635{
16081636 EXPECT_DECLS ;
0 commit comments