Skip to content

Commit ee60365

Browse files
committed
Update API
1 parent 8074c49 commit ee60365

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

src/ocsp/clu_ocsp.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ static int ocspResponder(OcspResponderConfig* config)
634634
SOCKET_T clientfd = INVALID_SOCKET;
635635
int requestsProcessed = 0;
636636
int ret = WOLFCLU_SUCCESS;
637-
const char* caSubject;
638-
word32 caSubjectSz;
637+
char* caSubject = NULL;
638+
word32 caSubjectSz = 0;
639639
byte* caCertDer = NULL;
640640
word32 caCertDerSz = 0;
641641
byte* signerCertDer = NULL;
@@ -693,12 +693,25 @@ static int ocspResponder(OcspResponderConfig* config)
693693
goto cleanup;
694694
}
695695

696-
caSubject = wc_GetDecodedCertSubject(&caCert, &caSubjectSz);
697-
if (caSubject == NULL || caSubjectSz == 0) {
696+
/* First call: get required buffer size */
697+
if (wc_GetDecodedCertSubject(&caCert, NULL, &caSubjectSz) != LENGTH_ONLY_E ||
698+
caSubjectSz == 0) {
699+
wolfCLU_LogError("Could not get CA subject size");
700+
ret = WOLFCLU_FATAL_ERROR;
701+
goto cleanup;
702+
}
703+
caSubject = (char*)XMALLOC(caSubjectSz + 1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
704+
if (caSubject == NULL) {
705+
wolfCLU_LogError("Memory allocation failed for CA subject");
706+
ret = WOLFCLU_FATAL_ERROR;
707+
goto cleanup;
708+
}
709+
if (wc_GetDecodedCertSubject(&caCert, caSubject, &caSubjectSz) != 0) {
698710
wolfCLU_LogError("Could not get CA subject");
699711
ret = WOLFCLU_FATAL_ERROR;
700712
goto cleanup;
701713
}
714+
caSubject[caSubjectSz] = '\0';
702715

703716
/* Load index file if provided */
704717
if (config->indexFile) {
@@ -878,16 +891,12 @@ static int ocspResponder(OcspResponderConfig* config)
878891
wolfCLU_ServerClose(sockfd);
879892

880893
wc_FreeDecodedCert(&caCert);
881-
if (responder)
882-
wc_OcspResponder_free(responder);
883-
if (indexEntries)
884-
freeIndexEntries(indexEntries);
885-
if (caCertDer)
886-
XFREE(caCertDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
887-
if (signerCertDer)
888-
XFREE(signerCertDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
889-
if (signerKeyDer)
890-
XFREE(signerKeyDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
894+
wc_OcspResponder_free(responder);
895+
freeIndexEntries(indexEntries);
896+
XFREE(caCertDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
897+
XFREE(signerCertDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
898+
XFREE(signerKeyDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
899+
XFREE(caSubject, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
891900

892901
return ret;
893902
}

0 commit comments

Comments
 (0)