Skip to content

Commit

Permalink
ProcessCSR_ex: fix use after free.
Browse files Browse the repository at this point in the history
  • Loading branch information
philljj committed Oct 21, 2024
1 parent ea6e818 commit d9556a1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -13587,21 +13587,28 @@ static int ProcessCSR_ex(WOLFSSL* ssl, byte* input, word32* inOutIdx,

#ifdef WOLFSSL_SMALL_STACK
status = (CertStatus*)XMALLOC(sizeof(CertStatus), ssl->heap,
DYNAMIC_TYPE_OCSP_STATUS);
DYNAMIC_TYPE_OCSP_STATUS);
single = (OcspEntry*)XMALLOC(sizeof(OcspEntry), ssl->heap,
DYNAMIC_TYPE_OCSP_ENTRY);
DYNAMIC_TYPE_OCSP_ENTRY);
response = (OcspResponse*)XMALLOC(sizeof(OcspResponse), ssl->heap,
DYNAMIC_TYPE_OCSP_REQUEST);
DYNAMIC_TYPE_OCSP_REQUEST);

if (status == NULL || single == NULL || response == NULL) {
XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
if (status != NULL) {
XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
}
if (single != NULL) {
XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
}
if (response != NULL) {
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
}

return MEMORY_ERROR;
}
#endif

/* InitOcspResponse sets single and status to response struct. */
InitOcspResponse(response, single, status, input +*inOutIdx, status_length, ssl->heap);

if (OcspResponseDecode(response, SSL_CM(ssl), ssl->heap, 0) != 0)
Expand All @@ -13625,9 +13632,8 @@ static int ProcessCSR_ex(WOLFSSL* ssl, byte* input, word32* inOutIdx,
FreeOcspResponse(response);

#ifdef WOLFSSL_SMALL_STACK
XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
/* FreeOcspResponse frees status and single. */
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
#endif

WOLFSSL_LEAVE("ProcessCSR", ret);
Expand Down

0 comments on commit d9556a1

Please sign in to comment.