From: Ondřej Surý Date: Sat, 1 Feb 2020 17:24:43 +0000 (+0100) Subject: Change pk11_mem_get() so it cannot soft-fail X-Git-Tag: v9.14.11~20^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f4ca46d50019b79e28a9d0d191ec15a87f5eae3;p=thirdparty%2Fbind9.git Change pk11_mem_get() so it cannot soft-fail (cherry picked from commit 05ae2e48ab1bd4477a4acec11a18c2fdd1694cb9) --- diff --git a/lib/isc/pk11.c b/lib/isc/pk11.c index 234a07e81f3..49861f2e1de 100644 --- a/lib/isc/pk11.c +++ b/lib/isc/pk11.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -154,8 +156,12 @@ pk11_mem_get(size_t size) { ptr = isc_mem_get(pk11_mctx, size); else { ptr = malloc(size); - if (ptr != NULL) - allocsize += (int)size; + if (ptr == NULL && size != 0) { + char strbuf[ISC_STRERRORSIZE]; + strerror_r(errno, strbuf, sizeof(strbuf)); + isc_error_fatal(__FILE__, __LINE__, "malloc failed: %s", + strbuf); + } } UNLOCK(&alloclock); @@ -326,8 +332,6 @@ pk11_get_session(pk11_context_t *ctx, pk11_optype_t optype, UNLOCK(&sessionlock); sp = pk11_mem_get(sizeof(*sp)); - if (sp == NULL) - return (ISC_R_NOMEMORY); sp->magic = SES_MAGIC; sp->token = token; sp->session = CK_INVALID_HANDLE; @@ -482,7 +486,6 @@ scan_slots(void) { if (slotCount == 0) return; slotList = pk11_mem_get(sizeof(CK_SLOT_ID) * slotCount); - RUNTIME_CHECK(slotList != NULL); PK11_FATALCHECK(pkcs_C_GetSlotList, (CK_FALSE, slotList, &slotCount)); for (i = 0; i < slotCount; i++) { @@ -493,7 +496,6 @@ scan_slots(void) { if (rv != CKR_OK) continue; token = pk11_mem_get(sizeof(*token)); - RUNTIME_CHECK(token != NULL); token->magic = TOK_MAGIC; token->slotid = slot; ISC_LINK_INIT(token, link);