]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
3573. [bug] "rndc addzone" and "rndc delzone" incorrectly handled zone
authorCurtis Blackburn <ckb@isc.org>
Fri, 10 May 2013 21:12:27 +0000 (16:12 -0500)
committerCurtis Blackburn <ckb@isc.org>
Fri, 10 May 2013 21:12:27 +0000 (16:12 -0500)
names containing punctuation marks and other nonstandard
characters. [RT #33419]

CHANGES
bin/named/server.c
bin/tests/system/addzone/ns2/added.db
bin/tests/system/addzone/tests.sh [changed mode: 0644->0755]

diff --git a/CHANGES b/CHANGES
index e8acb429ed53dd68ef29deb708aa0153b972d80b..4e19c572d64c0bf28331c252c9237e7d943938ca 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+3573.  [bug]           "rndc addzone" and "rndc delzone" incorrectly handled zone 
+                       names containing punctuation marks and other nonstandard 
+                       characters. [RT #33419]
+
 3572.  [func]          Threads are now enabled by default on most
                        operating systems. [RT #25483]
 
index b6c1d7aadef2cd6f13395e21fb616f2a192690a7..98662e8a07bc0d461f0c7df824fdf0b093733a6d 100644 (file)
@@ -8280,11 +8280,13 @@ ns_server_add_zone(ns_server_t *server, char *args) {
        const char          *viewname = NULL;
        dns_rdataclass_t     rdclass;
        dns_view_t          *view = 0;
-       isc_buffer_t         buf, *nbuf = NULL;
-       dns_name_t           dnsname;
+       isc_buffer_t         buf;
+       dns_fixedname_t      fname;
+       dns_name_t          *dnsname;
        dns_zone_t          *zone = NULL;
        FILE                *fp = NULL;
        struct cfg_context  *cfg = NULL;
+       char                namebuf[DNS_NAME_FORMATSIZE];
 
        /* Try to parse the argument string */
        arglen = strlen(args);
@@ -8298,10 +8300,10 @@ ns_server_add_zone(ns_server_t *server, char *args) {
        zonename = cfg_obj_asstring(cfg_tuple_get(parms, "name"));
        isc_buffer_constinit(&buf, zonename, strlen(zonename));
        isc_buffer_add(&buf, strlen(zonename));
-       dns_name_init(&dnsname, NULL);
-       isc_buffer_allocate(server->mctx, &nbuf, 256);
-       dns_name_setbuffer(&dnsname, nbuf);
-       CHECK(dns_name_fromtext(&dnsname, &buf, dns_rootname, ISC_FALSE, NULL));
+
+       dns_fixedname_init(&fname);
+       dnsname = dns_fixedname_name(&fname);
+       CHECK(dns_name_fromtext(dnsname, &buf, dns_rootname, ISC_FALSE, NULL));
 
        /* Make sense of optional class argument */
        obj = cfg_tuple_get(parms, "class");
@@ -8330,7 +8332,7 @@ ns_server_add_zone(ns_server_t *server, char *args) {
        }
 
        /* Zone shouldn't already exist */
-       result = dns_zt_find(view->zonetable, &dnsname, 0, NULL, &zone);
+       result = dns_zt_find(view->zonetable, dnsname, 0, NULL, &zone);
        if (result == ISC_R_SUCCESS) {
                result = ISC_R_EXISTS;
                goto cleanup;
@@ -8372,7 +8374,7 @@ ns_server_add_zone(ns_server_t *server, char *args) {
                goto cleanup;
 
        /* Is it there yet? */
-       CHECK(dns_zt_find(view->zonetable, &dnsname, 0, NULL, &zone));
+       CHECK(dns_zt_find(view->zonetable, dnsname, 0, NULL, &zone));
 
        /*
         * Load the zone from the master file.  If this fails, we'll
@@ -8400,10 +8402,13 @@ ns_server_add_zone(ns_server_t *server, char *args) {
        /* Flag the zone as having been added at runtime */
        dns_zone_setadded(zone, ISC_TRUE);
 
-       /* Emit just the zone name from args */
-       CHECK(isc_stdio_write("zone ", 5, 1, fp, NULL));
-       CHECK(isc_stdio_write(zonename, strlen(zonename), 1, fp, NULL));
-       CHECK(isc_stdio_write(" ", 1, 1, fp, NULL));
+       /* Emit the zone name, quoted and escaped */
+       isc_buffer_init(&buf, namebuf, sizeof(namebuf));
+       CHECK(dns_name_totext(dnsname, ISC_TRUE, &buf));
+       isc_buffer_putuint8(&buf, 0);
+       CHECK(isc_stdio_write("zone \"", 6, 1, fp, NULL));
+       CHECK(isc_stdio_write(namebuf, strlen(namebuf), 1, fp, NULL));
+       CHECK(isc_stdio_write("\" ", 2, 1, fp, NULL));
 
        /* Classname, if not default */
        if (classname != NULL && *classname != '\0') {
@@ -8447,8 +8452,6 @@ ns_server_add_zone(ns_server_t *server, char *args) {
                dns_zone_detach(&zone);
        if (view != NULL)
                dns_view_detach(&view);
-       if (nbuf != NULL)
-               isc_buffer_free(&nbuf);
 
        return (result);
 }
index 4c734cb6dacdf0566b610098acecd36e20a4d27c..3aa1debfeede99bf4f424118782427d93d0ee64c 100644 (file)
@@ -14,7 +14,7 @@
 
 ; $Id: added.db,v 1.2 2010/08/11 18:14:18 each Exp $
 
-$ORIGIN added.example.
+;$ORIGIN added.example.
 $TTL 300       ; 5 minutes
 @                       IN SOA mname1. . (
                                1          ; serial
old mode 100644 (file)
new mode 100755 (executable)
index 555a37b..28e9c65
@@ -51,6 +51,26 @@ n=`expr $n + 1`
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+echo "I:adding a zone that requires quotes ($n)"
+ret=0
+$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 addzone '"32/1.0.0.127-in-addr.added.example" { check-names ignore; type master; file "added.db"; };' 2>&1 | sed 's/^/I:ns2 /'
+$DIG $DIGOPTS @10.53.0.2 "a.32/1.0.0.127-in-addr.added.example" a > dig.out.ns2.$n || ret=1
+grep 'status: NOERROR' dig.out.ns2.$n > /dev/null || ret=1
+grep '^a.32/1.0.0.127-in-addr.added.example' dig.out.ns2.$n > /dev/null || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
+echo "I:adding a zone with a quote in the name ($n)"
+ret=0
+$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 addzone '"foo\"bar.example" { check-names ignore; type master; file "added.db"; };' 2>&1 | sed 's/^/I:ns2 /'
+$DIG $DIGOPTS @10.53.0.2 "a.foo\"bar.example" a > dig.out.ns2.$n || ret=1
+grep 'status: NOERROR' dig.out.ns2.$n > /dev/null || ret=1
+grep '^a.foo\\"bar.example' dig.out.ns2.$n > /dev/null || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
 echo "I:adding new zone with missing master file ($n)"
 ret=0
 $DIG $DIGOPTS +all @10.53.0.2 a.missing.example a > dig.out.ns2.pre.$n || ret=1
@@ -84,6 +104,16 @@ n=`expr $n + 1`
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+echo "I:deleting newly added zone with escaped quote ($n)"
+ret=0
+$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone "foo\\\"bar.example" 2>&1 | sed 's/^/I:ns2 /'
+$DIG $DIGOPTS @10.53.0.2 "a.foo\"bar.example" a > dig.out.ns2.$n
+grep 'status: REFUSED' dig.out.ns2.$n > /dev/null || ret=1
+grep "^a.foo\"bar.example" dig.out.ns2.$n > /dev/null && ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
 echo "I:attempt to delete a normally-loaded zone ($n)"
 ret=0
 $RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone normal.example 2> rndc.out.ns2.$n