@@ -687,13 +687,22 @@ int CheckCertCRL(WOLFSSL_CRL* crl, DecodedCert* cert)
687687#ifdef HAVE_CRL_UPDATE_CB
688688static void SetCrlInfo (CRL_Entry * entry , CrlInfo * info )
689689{
690- info -> issuerHash = (byte * )entry -> issuerHash ;
691- info -> issuerHashLen = CRL_DIGEST_SIZE ;
692- info -> lastDate = (byte * )entry -> lastDate ;
693- info -> lastDateMaxLen = MAX_DATE_SIZE ;
690+ /* Ensure the copy below stays within bounds. */
691+ wc_static_assert (sizeof (info -> issuerHashData ) == sizeof (entry -> issuerHash ));
692+
693+ /* Copy into info's own buffers so the pointers stay valid for the
694+ * lifetime of the CrlInfo, not just that of the source entry. */
695+ info -> issuerHashLen = sizeof (info -> issuerHashData );
696+ XMEMCPY (info -> issuerHashData , entry -> issuerHash ,
697+ sizeof (info -> issuerHashData ));
698+ info -> issuerHash = info -> issuerHashData ;
699+ info -> lastDateMaxLen = sizeof (info -> lastDateData );
700+ XMEMCPY (info -> lastDateData , entry -> lastDate , sizeof (info -> lastDateData ));
701+ info -> lastDate = info -> lastDateData ;
694702 info -> lastDateFormat = entry -> lastDateFormat ;
695- info -> nextDate = (byte * )entry -> nextDate ;
696- info -> nextDateMaxLen = MAX_DATE_SIZE ;
703+ info -> nextDateMaxLen = sizeof (info -> nextDateData );
704+ XMEMCPY (info -> nextDateData , entry -> nextDate , sizeof (info -> nextDateData ));
705+ info -> nextDate = info -> nextDateData ;
697706 info -> nextDateFormat = entry -> nextDateFormat ;
698707 info -> crlNumberSet = entry -> crlNumberSet ;
699708 if (info -> crlNumberSet )
@@ -702,13 +711,19 @@ static void SetCrlInfo(CRL_Entry* entry, CrlInfo *info)
702711
703712static void SetCrlInfoFromDecoded (DecodedCRL * entry , CrlInfo * info )
704713{
705- info -> issuerHash = (byte * )entry -> issuerHash ;
706- info -> issuerHashLen = SIGNER_DIGEST_SIZE ;
707- info -> lastDate = (byte * )entry -> lastDate ;
708- info -> lastDateMaxLen = MAX_DATE_SIZE ;
714+ /* Copy into info's own buffers so the pointers stay valid after the
715+ * decoded CRL is freed by the caller. */
716+ info -> issuerHashLen = sizeof (info -> issuerHashData );
717+ XMEMCPY (info -> issuerHashData , entry -> issuerHash ,
718+ sizeof (info -> issuerHashData ));
719+ info -> issuerHash = info -> issuerHashData ;
720+ info -> lastDateMaxLen = sizeof (info -> lastDateData );
721+ XMEMCPY (info -> lastDateData , entry -> lastDate , sizeof (info -> lastDateData ));
722+ info -> lastDate = info -> lastDateData ;
709723 info -> lastDateFormat = entry -> lastDateFormat ;
710- info -> nextDate = (byte * )entry -> nextDate ;
711- info -> nextDateMaxLen = MAX_DATE_SIZE ;
724+ info -> nextDateMaxLen = sizeof (info -> nextDateData );
725+ XMEMCPY (info -> nextDateData , entry -> nextDate , sizeof (info -> nextDateData ));
726+ info -> nextDate = info -> nextDateData ;
712727 info -> nextDateFormat = entry -> nextDateFormat ;
713728 info -> crlNumberSet = entry -> crlNumberSet ;
714729 if (info -> crlNumberSet )
0 commit comments