Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tests/api/test_tls_bounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,8 @@ int test_ProcessChainOCSPRequest_bounds(void)
ExpectNotNull(ssl = wolfSSL_new(ctx));
if (ssl != NULL) {
TLSX* ext = NULL;
DerBuffer* savedCert = ssl->buffers.certificate;
DerBuffer* savedChain = ssl->buffers.certChain;
ExpectIntEQ(TLSX_UseCertificateStatusRequest(&ssl->extensions,
WOLFSSL_CSR_OCSP, 0, ssl, ssl->heap, ssl->devId),
WOLFSSL_SUCCESS);
Expand All @@ -1475,10 +1477,14 @@ int test_ProcessChainOCSPRequest_bounds(void)
/* A certificate had to be loaded for wolfSSL_new() to succeed (see
* test_tls_bounds_load_server_cert()); clear both buffers back to
* NULL so ProcessChainOCSPRequest() sees exactly the "chain ==
* NULL" state under test. */
* NULL" state under test. The SSL owns these buffers (weOwnCert),
* so save and restore them - nulling them outright leaked the DER
* copy that wolfSSL_new() allocated. */
ssl->buffers.certChain = NULL;
ssl->buffers.certificate = NULL;
ExpectIntEQ(ProcessChainOCSPRequest(ssl), 0);
ssl->buffers.certificate = savedCert;
ssl->buffers.certChain = savedChain;
}
wolfSSL_free(ssl);
ssl = NULL;
Expand Down
22 changes: 22 additions & 0 deletions wolfcrypt/src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ static int wc_MemFailCount_AllocMem(void)

return ret;
}
/* An allocation was counted by wc_MemFailCount_AllocMem() above, but the
* underlying allocator then returned NULL (a caller-installed failing
* allocator via wolfSSL_SetAllocators(), or a genuine out-of-memory). No
* block exists to be freed, so undo the count to keep Total (allocs)
* balanced with Frees. */
static void wc_MemFailCount_AllocFailed(void)
{
wc_LockMutex(&memFailMutex);
if (mem_fail_allocs > 0) {
mem_fail_allocs--;
}
wc_UnLockMutex(&memFailMutex);
}
static void wc_MemFailCount_FreeMem(void)
{
wc_LockMutex(&memFailMutex);
Expand Down Expand Up @@ -406,10 +419,19 @@ void* wolfSSL_Malloc(size_t size)
free(res); /* native heap */
}
gMemFailCount = gMemFailCountSeed; /* reset */
#ifdef WOLFSSL_MEM_FAIL_COUNT
wc_MemFailCount_AllocFailed();
#endif
return NULL;
}
#endif

#ifdef WOLFSSL_MEM_FAIL_COUNT
if (res == NULL) {
wc_MemFailCount_AllocFailed();
}
#endif

return res;
}

Expand Down
Loading