@@ -177,6 +177,16 @@ static int LoadFile(const char* filename, byte** buf, word32* bufSz, int* isPem)
177177
178178 /* Check if PEM format by looking for -----BEGIN */
179179 if (isPem ) {
180+ /* Reallocate with space for null terminator for XSTRSTR */
181+ byte * tmp = (byte * )XREALLOC (* buf , (word32 )sz + 1 , NULL ,
182+ DYNAMIC_TYPE_TMP_BUFFER );
183+ if (tmp == NULL ) {
184+ XFREE (* buf , NULL , DYNAMIC_TYPE_TMP_BUFFER );
185+ * buf = NULL ;
186+ return MEMORY_E ;
187+ }
188+ * buf = tmp ;
189+ (* buf )[sz ] = '\0' ;
180190 * isPem = (XSTRSTR ((char * )* buf , "-----BEGIN" ) != NULL ) ? 1 : 0 ;
181191 }
182192
@@ -749,6 +759,9 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
749759 opts .sendCerts = 1 ;
750760 opts .readyFile = NULL ;
751761
762+ /* Initialize caCert */
763+ XMEMSET (& caCert , 0 , sizeof (caCert ));
764+
752765 /* Parse command line arguments */
753766 while ((ch = mygetopt_long (argc , argv , "?p:c:r:k:i:R:n:vx" ,
754767 long_options , 0 )) != -1 ) {
@@ -848,7 +861,6 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
848861 }
849862
850863 /* Parse CA certificate to get subject */
851- XMEMSET (& caCert , 0 , sizeof (caCert ));
852864 wc_InitDecodedCert (& caCert , caCertDer , caCertDerSz , NULL );
853865 ret = wc_ParseCert (& caCert , CERT_TYPE , 0 , NULL );
854866 if (ret != 0 ) {
0 commit comments