2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-04 00:25:29 +00:00

Fixed some memory management problems in sortlist code [rt17216]

This commit is contained in:
Evan Hunt
2007-10-12 04:17:18 +00:00
parent 4f7715809f
commit dabe7f50bb
5 changed files with 48 additions and 26 deletions

View File

@@ -1,5 +1,7 @@
--- 9.5.0a7 released --- --- 9.5.0a7 released ---
2252. [bug] Fixed memory leaks in sortlist code [RT #17216]
2251. [placeholder] 2251. [placeholder]
2250. [func] New flag 'memstatistics' to state whether the 2250. [func] New flag 'memstatistics' to state whether the

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: aclconf.c,v 1.11 2007/09/14 01:46:05 marka Exp $ */ /* $Id: aclconf.c,v 1.12 2007/10/12 04:17:18 each Exp $ */
#include <config.h> #include <config.h>
@@ -81,7 +81,7 @@ get_acl_def(const cfg_obj_t *cctx, const char *name, const cfg_obj_t **ret) {
static isc_result_t static isc_result_t
convert_named_acl(const cfg_obj_t *nameobj, const cfg_obj_t *cctx, convert_named_acl(const cfg_obj_t *nameobj, const cfg_obj_t *cctx,
isc_log_t *lctx, cfg_aclconfctx_t *ctx, isc_log_t *lctx, cfg_aclconfctx_t *ctx,
isc_mem_t *mctx, int nest_level, isc_mem_t *mctx, unsigned int nest_level,
dns_acl_t **target) dns_acl_t **target)
{ {
isc_result_t result; isc_result_t result;
@@ -166,7 +166,7 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
isc_log_t *lctx, isc_log_t *lctx,
cfg_aclconfctx_t *ctx, cfg_aclconfctx_t *ctx,
isc_mem_t *mctx, isc_mem_t *mctx,
int nest_level, unsigned int nest_level,
dns_acl_t **target) dns_acl_t **target)
{ {
isc_result_t result; isc_result_t result;
@@ -185,7 +185,8 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
* nested ACL's contents should just be absorbed into its * nested ACL's contents should just be absorbed into its
* parent ACL. * parent ACL.
*/ */
dacl = *target; dns_acl_attach(*target, &dacl);
dns_acl_detach(target);
} else { } else {
/* /*
* Need to allocate a new ACL structure. Count the items * Need to allocate a new ACL structure. Count the items
@@ -193,7 +194,10 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
* elements (even though some or all of them may end up in * elements (even though some or all of them may end up in
* the iptable instead of the element array). * the iptable instead of the element array).
*/ */
result = dns_acl_create(mctx, cfg_list_length(caml), &dacl); isc_boolean_t recurse = ISC_TF(nest_level == 0);
result = dns_acl_create(mctx,
cfg_list_length(caml, recurse),
&dacl);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
} }
@@ -219,8 +223,10 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
* merged into the main iptable. * merged into the main iptable.
*/ */
iptab = dacl->iptable; iptab = dacl->iptable;
if (nest_level > 0) {
result = dns_acl_create(mctx, cfg_list_length(ce), if (nest_level != 0) {
result = dns_acl_create(mctx,
cfg_list_length(ce, ISC_FALSE),
&de->nestedacl); &de->nestedacl);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
@@ -238,7 +244,7 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
if (nest_level > 0) { if (nest_level != 0) {
/* This prefix is going into a nested acl */ /* This prefix is going into a nested acl */
de->type = dns_aclelementtype_nestedacl; de->type = dns_aclelementtype_nestedacl;
de->negative = neg; de->negative = neg;
@@ -300,10 +306,11 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
result = get_acl_def(cctx, name, NULL); result = get_acl_def(cctx, name, NULL);
if (result == ISC_R_SUCCESS) { if (result == ISC_R_SUCCESS) {
/* found it in acl definitions */ /* found it in acl definitions */
inneracl = NULL; if (inneracl != NULL)
dns_acl_detach(&inneracl);
result = convert_named_acl(ce, cctx, result = convert_named_acl(ce, cctx,
lctx, ctx, mctx, lctx, ctx, mctx,
(nest_level > 0) (nest_level != 0)
? (nest_level - 1) ? (nest_level - 1)
: 0, : 0,
&inneracl); &inneracl);
@@ -311,17 +318,22 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
if (nest_level) { if (nest_level != 0) {
de->type = dns_aclelementtype_nestedacl, de->type = dns_aclelementtype_nestedacl;
de->negative = neg; de->negative = neg;
de->nestedacl = inneracl; if(de->nestedacl != NULL)
dns_acl_detach(&de->nestedacl);
dns_acl_attach(inneracl,
&de->nestedacl);
dns_acl_detach(&inneracl);
/* Fall through */
} else { } else {
dns_acl_merge(dacl, inneracl, dns_acl_merge(dacl, inneracl,
ISC_TF(!neg)); ISC_TF(!neg));
dns_acl_detach(&inneracl); dns_acl_detach(&inneracl);
}
continue; continue;
} }
}
} else { } else {
cfg_obj_log(ce, lctx, ISC_LOG_WARNING, cfg_obj_log(ce, lctx, ISC_LOG_WARNING,
"address match list contains " "address match list contains "
@@ -335,7 +347,8 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
* and keyname elements, and nested ACLs if nest_level is * and keyname elements, and nested ACLs if nest_level is
* nonzero (i.e., in sortlists). * nonzero (i.e., in sortlists).
*/ */
if (nest_level > 0 && de->type != dns_aclelementtype_nestedacl) if (de->nestedacl != NULL &&
de->type != dns_aclelementtype_nestedacl)
dns_acl_detach(&de->nestedacl); dns_acl_detach(&de->nestedacl);
dacl->node_count++; dacl->node_count++;
@@ -346,10 +359,12 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
INSIST(dacl->length <= dacl->alloc); INSIST(dacl->length <= dacl->alloc);
} }
*target = dacl; dns_acl_attach(dacl, target);
return (ISC_R_SUCCESS); result = ISC_R_SUCCESS;
cleanup: cleanup:
if (inneracl != NULL)
dns_acl_detach(&inneracl);
dns_acl_detach(&dacl); dns_acl_detach(&dacl);
return (result); return (result);
} }

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: aclconf.h,v 1.9 2007/09/12 01:09:08 each Exp $ */ /* $Id: aclconf.h,v 1.10 2007/10/12 04:17:18 each Exp $ */
#ifndef ISCCFG_ACLCONF_H #ifndef ISCCFG_ACLCONF_H
#define ISCCFG_ACLCONF_H 1 #define ISCCFG_ACLCONF_H 1
@@ -55,7 +55,7 @@ cfg_acl_fromconfig(const cfg_obj_t *caml,
isc_log_t *lctx, isc_log_t *lctx,
cfg_aclconfctx_t *ctx, cfg_aclconfctx_t *ctx,
isc_mem_t *mctx, isc_mem_t *mctx,
int nest_level, unsigned int nest_level,
dns_acl_t **target); dns_acl_t **target);
/* /*
* Construct a new dns_acl_t from configuration data in 'caml' and * Construct a new dns_acl_t from configuration data in 'caml' and

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: cfg.h,v 1.43 2007/09/14 01:46:06 marka Exp $ */ /* $Id: cfg.h,v 1.44 2007/10/12 04:17:18 each Exp $ */
#ifndef ISCCFG_CFG_H #ifndef ISCCFG_CFG_H
#define ISCCFG_CFG_H 1 #define ISCCFG_CFG_H 1
@@ -348,10 +348,11 @@ cfg_list_next(const cfg_listelt_t *elt);
*/ */
unsigned int unsigned int
cfg_list_length(const cfg_obj_t *obj); cfg_list_length(const cfg_obj_t *obj, isc_boolean_t recurse);
/*%< /*%<
* Returns the length of a list of configure objects. If obj is * Returns the length of a list of configure objects. If obj is
* not a list, returns 0. * not a list, returns 0. If recurse is true, add in the length of
* all contained lists.
*/ */
const cfg_obj_t * const cfg_obj_t *

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: parser.c,v 1.126 2007/09/14 01:46:05 marka Exp $ */ /* $Id: parser.c,v 1.127 2007/10/12 04:17:18 each Exp $ */
/*! \file */ /*! \file */
@@ -1114,17 +1114,21 @@ cfg_list_next(const cfg_listelt_t *elt) {
* a list, return 0. * a list, return 0.
*/ */
unsigned int unsigned int
cfg_list_length(const cfg_obj_t *obj) { cfg_list_length(const cfg_obj_t *obj, isc_boolean_t recurse) {
const cfg_listelt_t *elt; const cfg_listelt_t *elt;
unsigned int count = 0; unsigned int count = 0;
if (obj == NULL || ! cfg_obj_islist(obj)) if (obj == NULL || !cfg_obj_islist(obj))
return (0U); return (0U);
for (elt = cfg_list_first(obj); for (elt = cfg_list_first(obj);
elt != NULL; elt != NULL;
elt = cfg_list_next(elt)) { elt = cfg_list_next(elt)) {
if (recurse && cfg_obj_islist(elt->obj)) {
count += cfg_list_length(elt->obj, recurse);
} else {
count++; count++;
} }
}
return (count); return (count);
} }