]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix view's zones reverting bug during reconfiguration
authorAram Sargsyan <aram@isc.org>
Wed, 1 Mar 2023 12:30:46 +0000 (12:30 +0000)
committerAram Sargsyan <aram@isc.org>
Wed, 1 Mar 2023 14:10:31 +0000 (14:10 +0000)
During reconfiguration, the configure_view() function reverts the
configured zones to the previous view in case if there is an error.

It uses the 'zones_configured' boolean variable to decide whether
it is required to revert the zones, i.e. the error happened after
all the zones were successfully configured.

The problem is that it does not account for the case when an error
happens during the configuration of one of the zones (not the first),
in which case there are zones that are already configured for the
new view (and they need to be reverted), and there are zones that
are not (starting from the failed one).

Since 'zones_configured' remains 'false', the configured zones are
not reverted.

Replace the 'zones_configured' variable with a pointer to the latest
successfully configured zone configuration element, and when reverting,
revert up to and including that zone.

bin/named/server.c

index a37aa4f378652487bb9fd8eeb473871cb0d07c3b..e4449f84ee0f8ce8fdb667835d80ea05f5925ce8 100644 (file)
@@ -4060,7 +4060,8 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        const cfg_obj_t *dyndb_list, *plugin_list;
        const cfg_obj_t *disabled;
        const cfg_obj_t *obj, *obj2;
-       const cfg_listelt_t *element;
+       const cfg_listelt_t *element = NULL;
+       const cfg_listelt_t *zone_element_latest = NULL;
        in_port_t port;
        dns_cache_t *cache = NULL;
        isc_result_t result;
@@ -4077,7 +4078,6 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        dns_dispatch_t *dispatch6 = NULL;
        bool rpz_configured = false;
        bool catz_configured = false;
-       bool zones_configured = false;
        bool shared_cache = false;
        int i = 0, j = 0, k = 0;
        const char *str;
@@ -4187,8 +4187,8 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
                const cfg_obj_t *zconfig = cfg_listelt_value(element);
                CHECK(configure_zone(config, zconfig, vconfig, view, viewlist,
                                     kasplist, actx, false, old_rpz_ok, false));
+               zone_element_latest = element;
        }
-       zones_configured = true;
 
        /*
         * Check that a primary or secondary zone was found for each
@@ -6039,7 +6039,7 @@ cleanup:
                        dns_view_detach(&pview);
                }
 
-               if (zones_configured) {
+               if (zone_element_latest != NULL) {
                        for (element = cfg_list_first(zonelist);
                             element != NULL; element = cfg_list_next(element))
                        {
@@ -6047,6 +6047,13 @@ cleanup:
                                        cfg_listelt_value(element);
                                configure_zone_setviewcommit(result, zconfig,
                                                             view);
+                               if (element == zone_element_latest) {
+                                       /*
+                                        * This was the latest element that was
+                                        * successfully configured earlier.
+                                        */
+                                       break;
+                               }
                        }
                }
        }