]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4624. [bug] Check isc_mem_strdup results in dns_view_setnewzones.
authorMark Andrews <marka@isc.org>
Thu, 11 May 2017 10:31:03 +0000 (20:31 +1000)
committerMark Andrews <marka@isc.org>
Thu, 11 May 2017 10:31:03 +0000 (20:31 +1000)
                        [RT #45210]

CHANGES
bin/named/server.c
lib/dns/include/dns/view.h
lib/dns/view.c

diff --git a/CHANGES b/CHANGES
index f27645cd8da943996d048a57859a92f3eefbf287..c886da9f0b212e4741bd0843593bdec12e8f5980 100644 (file)
--- 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]
 
index 57ec84fff82e3e37a140f0bf8bd4c23dc76c9ebc..2a26bb79dad3fdf927a9e4ed7e6302a171fedbe7 100644 (file)
@@ -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);
index a515f76103d84dd8e651bfedb1df182392c30f27..6f46e202adb88ae5a411fe8a0f73a9d38d2689e3 100644 (file)
@@ -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
index 281876f1b08bc500d57b330ac5e51a6a25c82a84..5b420395fb559ee4c89997adf6cf4057e8043e6e 100644 (file)
@@ -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