@@ -215,6 +215,7 @@ int test_ocsp_basic_verify(void)
215215 ptr = (const unsigned char * )resp ;
216216 ExpectNotNull (
217217 response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr , sizeof (resp )));
218+ ExpectPtrEq (ptr , (const unsigned char * )resp + sizeof (resp ));
218219 ExpectIntEQ (response -> responseStatus , 0 );
219220 ExpectIntEQ (response -> responderIdType , OCSP_RESPONDER_ID_NAME );
220221 ExpectBufEQ (response -> responderId .nameHash , cert .subjectHash ,
@@ -225,6 +226,8 @@ int test_ocsp_basic_verify(void)
225226 ptr = (const unsigned char * )resp_rid_bykey ;
226227 ExpectNotNull (response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr ,
227228 sizeof (resp_rid_bykey )));
229+ ExpectPtrEq (ptr , (const unsigned char * )resp_rid_bykey +
230+ sizeof (resp_rid_bykey ));
228231 ExpectIntEQ (response -> responseStatus , 0 );
229232 ExpectIntEQ (response -> responderIdType , OCSP_RESPONDER_ID_KEY );
230233 ExpectBufEQ (response -> responderId .keyHash , cert .subjectKeyHash ,
@@ -235,6 +238,7 @@ int test_ocsp_basic_verify(void)
235238 ptr = (const unsigned char * )resp_nocert ;
236239 ExpectNotNull (
237240 response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr , sizeof (resp_nocert )));
241+ ExpectPtrEq (ptr , (const unsigned char * )resp_nocert + sizeof (resp_nocert ));
238242 ExpectIntEQ (response -> responseStatus , 0 );
239243 wolfSSL_OCSP_RESPONSE_free (response );
240244
@@ -246,6 +250,7 @@ int test_ocsp_basic_verify(void)
246250 ptr = (const unsigned char * )resp ;
247251 ExpectNotNull (
248252 response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr , sizeof (resp )));
253+ ExpectPtrEq (ptr , (const unsigned char * )resp + sizeof (resp ));
249254 /* no verify signer certificate */
250255 ExpectIntEQ (wolfSSL_OCSP_basic_verify (response , NULL , NULL , OCSP_NOVERIFY ),
251256 WOLFSSL_SUCCESS );
@@ -272,6 +277,7 @@ int test_ocsp_basic_verify(void)
272277 ptr = (const unsigned char * )resp_nocert ;
273278 ExpectNotNull (
274279 response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr , sizeof (resp_nocert )));
280+ ExpectPtrEq (ptr , (const unsigned char * )resp_nocert + sizeof (resp_nocert ));
275281 ExpectIntEQ (wolfSSL_OCSP_basic_verify (response , certs , store , 0 ),
276282 WOLFSSL_SUCCESS );
277283 wolfSSL_OCSP_RESPONSE_free (response );
@@ -281,6 +287,7 @@ int test_ocsp_basic_verify(void)
281287 ptr = (const unsigned char * )resp ;
282288 ExpectNotNull (
283289 response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr , sizeof (resp )));
290+ ExpectPtrEq (ptr , (const unsigned char * )resp + sizeof (resp ));
284291 ExpectIntEQ (wolfSSL_OCSP_basic_verify (response , NULL , store , 0 ),
285292 WOLFSSL_SUCCESS );
286293 /* make invalid signature */
@@ -311,6 +318,7 @@ int test_ocsp_basic_verify(void)
311318 ptr = (const unsigned char * )resp_nocert ;
312319 ExpectNotNull (
313320 response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr , sizeof (resp_nocert )));
321+ ExpectPtrEq (ptr , (const unsigned char * )resp_nocert + sizeof (resp_nocert ));
314322 ExpectIntNE (wolfSSL_OCSP_basic_verify (response , NULL , store , 0 ),
315323 WOLFSSL_SUCCESS );
316324 wolfSSL_OCSP_RESPONSE_free (response );
@@ -332,6 +340,7 @@ int test_ocsp_basic_verify(void)
332340 ptr = (const unsigned char * )resp_multi ;
333341 ExpectNotNull (
334342 response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr , sizeof (resp_multi )));
343+ ExpectPtrEq (ptr , (const unsigned char * )resp_multi + sizeof (resp_multi ));
335344 ExpectIntEQ (wolfSSL_OCSP_basic_verify (response , certs , store , 0 ),
336345 WOLFSSL_SUCCESS );
337346 wolfSSL_OCSP_RESPONSE_free (response );
@@ -342,6 +351,8 @@ int test_ocsp_basic_verify(void)
342351 ptr = (const unsigned char * )resp_bad_noauth ;
343352 ExpectNotNull (response = wolfSSL_d2i_OCSP_RESPONSE (NULL , & ptr ,
344353 sizeof (resp_bad_noauth )));
354+ ExpectPtrEq (ptr , (const unsigned char * )resp_bad_noauth +
355+ sizeof (resp_bad_noauth ));
345356
346357 expectedRet = WOLFSSL_FAILURE ;
347358#ifdef WOLFSSL_NO_OCSP_ISSUER_CHECK
@@ -665,11 +676,51 @@ int test_ocsp_certid_enc_dec(void)
665676 wolfSSL_X509_free (issuer );
666677 return EXPECT_SUCCESS ();
667678}
679+ int test_ocsp_certid_dup (void )
680+ {
681+ EXPECT_DECLS ;
682+ WOLFSSL_OCSP_CERTID * certId = NULL ;
683+ WOLFSSL_OCSP_CERTID * certIdDup = NULL ;
684+ WOLFSSL_X509 * subject = NULL ;
685+ WOLFSSL_X509 * issuer = NULL ;
686+
687+ /* Load test certificates */
688+ ExpectNotNull (
689+ subject = wolfSSL_X509_load_certificate_file (
690+ "./certs/ocsp/intermediate1-ca-cert.pem" , WOLFSSL_FILETYPE_PEM ));
691+ ExpectNotNull (issuer = wolfSSL_X509_load_certificate_file (
692+ "./certs/ocsp/root-ca-cert.pem" , WOLFSSL_FILETYPE_PEM ));
693+
694+ /* Create CERTID from certificates */
695+ ExpectNotNull (certId = wolfSSL_OCSP_cert_to_id (NULL , subject , issuer ));
696+
697+ /* Dup */
698+ ExpectNotNull (certIdDup = wolfSSL_OCSP_CERTID_dup (certId ));
699+
700+ /* Verify the dup compares equal */
701+ ExpectIntEQ (wolfSSL_OCSP_id_cmp (certId , certIdDup ), 0 );
702+
703+ /* Verify status is a distinct allocation (deep copy) */
704+ ExpectPtrNE (certId -> status , certIdDup -> status );
705+
706+ /* Freeing both must not double-free (ASAN will catch it) */
707+ wolfSSL_OCSP_CERTID_free (certId );
708+ wolfSSL_OCSP_CERTID_free (certIdDup );
709+
710+ wolfSSL_X509_free (subject );
711+ wolfSSL_X509_free (issuer );
712+ return EXPECT_SUCCESS ();
713+ }
714+
668715#else /* !NO_SHA && OPENSSL_ALL && HAVE_OCSP && !WOLFSSL_SM3 && !WOLFSSL_SM2 */
669716int test_ocsp_certid_enc_dec (void )
670717{
671718 return TEST_SKIPPED ;
672719}
720+ int test_ocsp_certid_dup (void )
721+ {
722+ return TEST_SKIPPED ;
723+ }
673724#endif
674725
675726#if defined(HAVE_OCSP ) && defined(WOLFSSL_CERT_SETUP_CB ) && \
0 commit comments