fix leak with multiple entries

This commit is contained in:
JacobBarthelmeh 2022-10-26 09:29:06 -07:00
parent 29a5c04c2e
commit a26b89f66b
3 changed files with 16 additions and 6 deletions

View File

@ -312,6 +312,7 @@ int CheckOcspResponse(WOLFSSL_OCSP *ocsp, byte *response, int responseSz,
return MEMORY_E;
}
#endif
XMEMSET(ocspResponse, 0, sizeof(OcspResponse));
InitOcspResponse(ocspResponse, newSingle, newStatus, response, responseSz,
ocsp->cm->heap);
@ -399,6 +400,7 @@ end:
ret = OCSP_LOOKUP_FAIL;
}
FreeOcspResponse(ocspResponse);
#ifdef WOLFSSL_SMALL_STACK
XFREE(newStatus, NULL, DYNAMIC_TYPE_OCSP_STATUS);
XFREE(newSingle, NULL, DYNAMIC_TYPE_OCSP_ENTRY);

View File

@ -1724,7 +1724,7 @@ static int test_wolfSSL_CheckOCSPResponse(void)
/* check loading a response with multiple certs */
{
WOLFSSL_CERT_MANAGER* cm = NULL;
OcspEntry entry[1];
OcspEntry *entry;
CertStatus status[1];
OcspRequest* request;
@ -1741,6 +1741,10 @@ static int test_wolfSSL_CheckOCSPResponse(void)
0x7E, 0x72, 0x15, 0x21
};
entry = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL,
DYNAMIC_TYPE_OPENSSL);
AssertNotNull(entry);
XMEMSET(entry, 0, sizeof(OcspEntry));
XMEMSET(status, 0, sizeof(CertStatus));
@ -1776,6 +1780,7 @@ static int test_wolfSSL_CheckOCSPResponse(void)
AssertIntEQ(XMEMCMP(status->serial, entry->status->serial,
status->serialSz), 0);
wolfSSL_OCSP_CERTID_free(entry);
wolfSSL_OCSP_REQUEST_free(request);
wolfSSL_CertManagerFree(cm);
}

View File

@ -34675,6 +34675,8 @@ void InitOcspResponse(OcspResponse* resp, OcspEntry* single, CertStatus* status,
void FreeOcspResponse(OcspResponse* resp)
{
OcspEntry *single, *next;
if (resp != NULL) {
for (single = resp->single; single; single = next) {
next = single->next;
if (single->isDynamic) {
@ -34683,6 +34685,7 @@ void FreeOcspResponse(OcspResponse* resp)
}
}
}
}
#ifdef WOLFSSL_ASN_TEMPLATE
/* ASN.1 template for OCSPResponse.