Compare commits

...

3 Commits

Author SHA1 Message Date
Ondřej Surý
c54606916a Add CHANGES entry for GL #674
(cherry picked from commit 37ff7f635b)
2018-12-21 09:24:07 +01:00
Ondřej Surý
cf697a85f7 Abort on allocation failure only if the memory functions are used internally in BIND 9
(cherry picked from commit c22241ae9009391c1d28085c5cf0009a6caef09c)
2018-12-21 09:24:07 +01:00
Ondřej Surý
cf3baa83a7 Abort on memory allocation failure
(cherry picked from commit 8de2451756)
2018-12-21 09:24:07 +01:00
2 changed files with 44 additions and 3 deletions

View File

@@ -25,6 +25,8 @@
5101. [bug] Fix default installation path for Python modules.
[GL #730]
5098. [func] Failed memory allocations are now fatal. [GL #674]
5097. [cleanup] Remove embedded ATF unit testing framework
from BIND source distribution. [GL !875]

View File

@@ -14,6 +14,7 @@
#include <config.h>
#include <inttypes.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -28,6 +29,7 @@
#include <isc/once.h>
#include <isc/ondestroy.h>
#include <isc/string.h>
#include <isc/strerror.h>
#include <isc/mutex.h>
#include <isc/print.h>
#include <isc/util.h>
@@ -861,11 +863,48 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size) {
static void *
default_memalloc(void *arg, size_t size) {
UNUSED(arg);
if (size == 0U)
if (size == 0U) {
size = 1;
}
return (malloc(size));
}
static void *
internal_memalloc(void *arg, size_t size) {
void *ptr;
UNUSED(arg);
if (size == 0U) {
size = 1;
}
ptr = malloc(size);
/*
* If the space cannot be allocated, a null pointer is returned. If the
* size of the space requested is zero, the behavior is
* implementation-defined: either a null pointer is returned, or the
* behavior is as if the size were some nonzero value, except that the
* returned pointer shall not be used to access an object.
* [ISO9899 § 7.22.3]
*
* [ISO9899]
* ISO/IEC WG 9899:2011: Programming languages - C.
* International Organization for Standardization, Geneva, Switzerland.
* http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf
*/
if (ptr == NULL && size != 0) {
char strbuf[ISC_STRERRORSIZE];
isc__strerror(errno, strbuf, sizeof(strbuf));
isc_error_fatal(__FILE__, __LINE__, "malloc failed: %s", strbuf);
}
return (ptr);
}
static void
default_memfree(void *arg, void *ptr) {
UNUSED(arg);
@@ -2707,7 +2746,7 @@ isc_mem_create(size_t init_max_size, size_t target_size, isc_mem_t **mctxp) {
if (isc_bind9)
return (isc_mem_createx2(init_max_size, target_size,
default_memalloc, default_memfree,
internal_memalloc, default_memfree,
NULL, mctxp, isc_mem_defaultflags));
LOCK(&createlock);
@@ -2726,7 +2765,7 @@ isc_mem_create2(size_t init_max_size, size_t target_size, isc_mem_t **mctxp,
{
if (isc_bind9)
return (isc_mem_createx2(init_max_size, target_size,
default_memalloc, default_memfree,
internal_memalloc, default_memfree,
NULL, mctxp, flags));
return (isc_mem_createx2(init_max_size, target_size,