diff --git a/CHANGES b/CHANGES index f27645cd8d..c886da9f0b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +4624. [bug] Check isc_mem_strdup results in dns_view_setnewzones. + [RT #45210] + 4622. [bug] Remove unnecessary escaping of semicolon in CAA and URI records. [RT #45216] diff --git a/bin/named/server.c b/bin/named/server.c index 57ec84fff8..2a26bb79da 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -5639,19 +5639,25 @@ setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig, allow = cfg_obj_asboolean(nz); if (!allow) { - dns_view_setnewzones(view, ISC_FALSE, NULL, NULL); - return (ISC_R_SUCCESS); + return (dns_view_setnewzones(view, ISC_FALSE, NULL, NULL)); } nzcfg = isc_mem_get(view->mctx, sizeof(*nzcfg)); if (nzcfg == NULL) { - dns_view_setnewzones(view, ISC_FALSE, NULL, NULL); + result = dns_view_setnewzones(view, ISC_FALSE, NULL, NULL); + RUNTIME_CHECK(result == ISC_R_SUCCESS); return (ISC_R_NOMEMORY); } - dns_view_setnewzones(view, allow, nzcfg, newzone_cfgctx_destroy); - memset(nzcfg, 0, sizeof(*nzcfg)); + + result = dns_view_setnewzones(view, allow, nzcfg, + newzone_cfgctx_destroy); + if (result != ISC_R_SUCCESS) { + isc_mem_put(view->mctx, nzcfg, sizeof(*nzcfg)); + return (ISC_R_NOMEMORY); + } + isc_mem_attach(view->mctx, &nzcfg->mctx); cfg_obj_attach(config, &nzcfg->config); cfg_parser_attach(parser, &nzcfg->parser); diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index a515f76103..6f46e202ad 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -1146,7 +1146,7 @@ dns_view_untrust(dns_view_t *view, dns_name_t *keyname, * \li 'dnskey' is valid. */ -void +isc_result_t dns_view_setnewzones(dns_view_t *view, isc_boolean_t allow, void *cfgctx, void (*cfg_destroy)(void **)); /*%< @@ -1165,6 +1165,10 @@ dns_view_setnewzones(dns_view_t *view, isc_boolean_t allow, void *cfgctx, * * Requires: * \li 'view' is valid. + * + * Returns: + * \li ISC_R_SUCCESS + * \li ISC_R_NOMEMORY */ void @@ -1183,14 +1187,14 @@ dns_view_searchdlz(dns_view_t *view, dns_name_t *name, * findzone method. If successful, '*dbp' is set to point to the * DLZ database. * - * Returns: - * \li ISC_R_SUCCESS - * \li ISC_R_NOTFOUND - * * Requires: * \li 'view' is valid. * \li 'name' is not NULL. * \li 'dbp' is not NULL and *dbp is NULL. + * + * Returns: + * \li ISC_R_SUCCESS + * \li ISC_R_NOTFOUND */ ISC_LANG_ENDDECLS diff --git a/lib/dns/view.c b/lib/dns/view.c index 281876f1b0..5b420395fb 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -281,6 +281,7 @@ static inline void destroy(dns_view_t *view) { dns_dns64_t *dns64; dns_dlzdb_t *dlzdb; + isc_result_t result; REQUIRE(!ISC_LINK_LINKED(view, link)); REQUIRE(isc_refcount_current(&view->references) == 0); @@ -295,7 +296,6 @@ destroy(dns_view_t *view) { dns_peerlist_detach(&view->peers); if (view->dynamickeys != NULL) { - isc_result_t result; char template[20]; char keyfile[20]; FILE *fp = NULL; @@ -453,7 +453,8 @@ destroy(dns_view_t *view) { dns_zone_detach(&view->managed_keys); if (view->redirect != NULL) dns_zone_detach(&view->redirect); - dns_view_setnewzones(view, ISC_FALSE, NULL, NULL); + result = dns_view_setnewzones(view, ISC_FALSE, NULL, NULL); + RUNTIME_CHECK(result == ISC_R_SUCCESS); dns_fwdtable_destroy(&view->fwdtable); dns_aclenv_destroy(&view->aclenv); DESTROYLOCK(&view->lock); @@ -1853,7 +1854,7 @@ dns_view_untrust(dns_view_t *view, dns_name_t *keyname, #define NZF ".nzf" -void +isc_result_t dns_view_setnewzones(dns_view_t *view, isc_boolean_t allow, void *cfgctx, void (*cfg_destroy)(void **)) { @@ -1876,9 +1877,12 @@ dns_view_setnewzones(dns_view_t *view, isc_boolean_t allow, void *cfgctx, /* Truncate the hash at 16 chars; full length is overkill */ isc_string_printf(buffer + 16, sizeof(NZF), "%s", NZF); view->new_zone_file = isc_mem_strdup(view->mctx, buffer); + if (view->new_zone_file == NULL) + return (ISC_R_NOMEMORY); view->new_zone_config = cfgctx; view->cfg_destroy = cfg_destroy; } + return (ISC_R_SUCCESS); } isc_result_t