]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4849. [bug] Duplicate zones could appear in the .nzf file if
authorMark Andrews <marka@isc.org>
Wed, 20 Dec 2017 06:13:58 +0000 (17:13 +1100)
committerMark Andrews <marka@isc.org>
Wed, 3 Jan 2018 22:49:25 +0000 (09:49 +1100)
                        addzone failed. [RT #46435]

(cherry picked from commit 2d7f89b9c76646baca3d65a938844f1f90157d83)

CHANGES
bin/named/server.c
bin/tests/system/addzone/ns3/e.db [new file with mode: 0644]
bin/tests/system/addzone/tests.sh
bin/tests/system/feature-test.c

diff --git a/CHANGES b/CHANGES
index 46a429d3ede98b1508f690f5a97da7414c67e2c8..2e6f9b19d7faad61fc953c023efbf9d3d69ee7c8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,9 @@
 4850.  [bug]           Named failed to restart with multiple added zones in
                        lmdb database. [RT #46889]
 
+4849.  [bug]           Duplicate zones could appear in the .nzf file if
+                       addzone failed. [RT #46435]
+
        --- 9.12.0rc1 released ---
 
 4841.  [bug]           Address -fsanitize=undefined warnings. [RT #46786]
index b557c8eca7da918ccbfbd2b73c986dc5f6b7d2c9..b9dcb3419f8c7199a1b881dfda4cd725e08fd472 100644 (file)
@@ -12608,6 +12608,7 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
        dns_zone_t *zone = NULL;
 #ifndef HAVE_LMDB
        FILE *fp = NULL;
+       isc_boolean_t cleanup_config = ISC_FALSE;
 #else /* HAVE_LMDB */
        MDB_txn *txn = NULL;
        MDB_dbi dbi;
@@ -12700,14 +12701,15 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
         * we've created. If there was a previous one, merge the new
         * zone into it.
         */
-       if (cfg->nzf_config == NULL)
+       if (cfg->nzf_config == NULL) {
                cfg_obj_attach(zoneconf, &cfg->nzf_config);
-       else {
+       else {
                cfg_obj_t *z;
                DE_CONST(zoneobj, z);
                CHECK(cfg_parser_mapadd(cfg->add_parser,
                                        cfg->nzf_config, z, "zone"));
        }
+       cleanup_config = ISC_TRUE;
 #endif /* HAVE_LMDB */
 
        /*
@@ -12753,6 +12755,12 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
 #ifndef HAVE_LMDB
        if (fp != NULL)
                (void)isc_stdio_close(fp);
+       if (result != ISC_R_SUCCESS && cleanup_config) {
+               tresult = delete_zoneconf(view, cfg->add_parser,
+                                        cfg->nzf_config, name,
+                                        NULL);
+               RUNTIME_CHECK(tresult == ISC_R_SUCCESS);
+       }
 #else /* HAVE_LMDB */
        if (txn != NULL)
                (void) nzd_close(&txn, ISC_FALSE);
diff --git a/bin/tests/system/addzone/ns3/e.db b/bin/tests/system/addzone/ns3/e.db
new file mode 100644 (file)
index 0000000..620f4cd
--- /dev/null
@@ -0,0 +1,3 @@
+@      SOA     ns3 hostmaster 0 0 0 0 0
+@      NS      ns3
+ns3    A       10.53.0.3
index ea5ed479954e7ca2048360646f388e195d80c8a6..4692abaec53992eda370d78f9dbc629f17293c47 100755 (executable)
@@ -672,6 +672,20 @@ n=`expr $n + 1`
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+if ! $FEATURETEST --with-lmdb
+then
+    echo "I:check that addzone is fully reversed on failure (--with-lmdb=no) ($n)"
+    ret=0
+    $RNDC -c ../common/rndc.conf -s 10.53.0.3 -p 9953 addzone "test1.baz" '{ type master; file "e.db"; };' > /dev/null 2>&1 || ret=1
+    $RNDC -c ../common/rndc.conf -s 10.53.0.3 -p 9953 addzone "test2.baz" '{ type master; file "dne.db"; };' > /dev/null 2>&1 && ret=1
+    $RNDC -c ../common/rndc.conf -s 10.53.0.3 -p 9953 addzone "test3.baz" '{ type master; file "e.db"; };' > /dev/null 2>&1 || ret=1
+    $RNDC -c ../common/rndc.conf -s 10.53.0.3 -p 9953 delzone "test3.baz" > /dev/null 2>&1 || ret=1
+    grep test2.baz ns3/_default.nzf > /dev/null && ret=1
+    n=`expr $n + 1`
+    if [ $ret != 0 ]; then echo "I:failed"; fi
+    status=`expr $status + $ret`
+fi
+
 echo "I:check that named restarts with multiple added zones ($n)"
 ret=0
 $RNDC -c ../common/rndc.conf -s 10.53.0.3 -p 9953 addzone "test4.baz" '{ type master; file "e.db"; };' > /dev/null 2>&1 || ret=1
index 155ea7615e84ed5fc8e3d4581606f12cff74a50c..6ef94b216520ee9405583c0ef6d92f5f09f8a2d3 100644 (file)
@@ -45,6 +45,7 @@ usage() {
        fprintf(stderr, "       --rpz-nsdname\n");
        fprintf(stderr, "       --rpz-nsip\n");
        fprintf(stderr, "       --with-idn\n");
+       fprintf(stderr, "       --with-lmdb\n");
 }
 
 int
@@ -156,6 +157,14 @@ main(int argc, char **argv) {
 #endif
        }
 
+       if (strcmp(argv[1], "--with-lmdb") == 0) {
+#ifdef HAVE_LMDB
+               return (0);
+#else
+               return (1);
+#endif
+       }
+
        if (strcmp(argv[1], "--ipv6only=no") == 0) {
 #ifdef WIN32
                return (0);