]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
3917. [bug] dig, nslookup and host now continue on names that are
authorMark Andrews <marka@isc.org>
Thu, 21 Aug 2014 08:05:55 +0000 (18:05 +1000)
committerMark Andrews <marka@isc.org>
Thu, 21 Aug 2014 08:11:52 +0000 (18:11 +1000)
                        too long after applying a search list elements.
                        [RT #36892]

CHANGES
bin/dig/dighost.c
bin/dig/include/dig/dig.h
bin/tests/system/conf.sh.in
bin/tests/system/nslookup/clean.sh [new file with mode: 0644]
bin/tests/system/nslookup/ns1/named.conf [new file with mode: 0644]
bin/tests/system/nslookup/setup.sh [new file with mode: 0644]
bin/tests/system/nslookup/tests.sh [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 3c8126f306d95c367b159c6d8ef66eafcf4901dc..677b762e68007cb08399d3dae656a35aa07c8647 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+3917.  [bug]           dig, nslookup and host now continue on names that are
+                       too long after applying a search list elements.
+                       [RT #36892]
+
 3916.  [contrib]       zone2sqlite checked wrong result code.  Address
                        compiler warnings. [RT #36931]
 
index 371dbe5f7f11e37822e22d63cce8f554a38087c9..e0194c39bfd4000952386a8f006a910ab2844687 100644 (file)
@@ -371,6 +371,12 @@ launch_next_query(dig_query_t *query, isc_boolean_t include_question);
 static void
 send_tcp_connect(dig_query_t *query);
 
+static void
+check_next_lookup(dig_lookup_t *lookup);
+
+static isc_boolean_t
+next_origin(dig_lookup_t *oldlookup);
+
 static void *
 mem_alloc(void *arg, size_t size) {
        return (isc_mem_get(arg, size));
@@ -1705,8 +1711,10 @@ start_lookup(void) {
                }
        novalidation:
 #endif
-               setup_lookup(current_lookup);
-               do_lookup(current_lookup);
+               if (setup_lookup(current_lookup))
+                       do_lookup(current_lookup);
+               else if (next_origin(current_lookup))
+                       check_next_lookup(current_lookup);
        } else {
                check_if_done();
        }
@@ -1907,8 +1915,8 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section)
  * Return ISC_TRUE iff there was another searchlist entry.
  */
 static isc_boolean_t
-next_origin(dig_query_t *query) {
-       dig_lookup_t *lookup;
+next_origin(dig_lookup_t *oldlookup) {
+       dig_lookup_t *newlookup;
        dig_searchlist_t *search;
        dns_fixedname_t fixed;
        dns_name_t *name;
@@ -1917,7 +1925,7 @@ next_origin(dig_query_t *query) {
        INSIST(!free_now);
 
        debug("next_origin()");
-       debug("following up %s", query->lookup->textname);
+       debug("following up %s", oldlookup->textname);
 
        if (!usesearch)
                /*
@@ -1931,30 +1939,30 @@ next_origin(dig_query_t *query) {
         */
        dns_fixedname_init(&fixed);
        name = dns_fixedname_name(&fixed);
-       result = dns_name_fromstring2(name, query->lookup->textname, NULL,
+       result = dns_name_fromstring2(name, oldlookup->textname, NULL,
                                      0, NULL);
        if (result == ISC_R_SUCCESS &&
            (dns_name_isabsolute(name) ||
             (int)dns_name_countlabels(name) > ndots))
                return (ISC_FALSE);
 
-       if (query->lookup->origin == NULL && !query->lookup->need_search)
+       if (oldlookup->origin == NULL && !oldlookup->need_search)
                /*
                 * Then we just did rootorg; there's nothing left.
                 */
                return (ISC_FALSE);
-       if (query->lookup->origin == NULL && query->lookup->need_search) {
-               lookup = requeue_lookup(query->lookup, ISC_TRUE);
-               lookup->origin = ISC_LIST_HEAD(search_list);
-               lookup->need_search = ISC_FALSE;
+       if (oldlookup->origin == NULL && oldlookup->need_search) {
+               newlookup = requeue_lookup(oldlookup, ISC_TRUE);
+               newlookup->origin = ISC_LIST_HEAD(search_list);
+               newlookup->need_search = ISC_FALSE;
        } else {
-               search = ISC_LIST_NEXT(query->lookup->origin, link);
-               if (search == NULL && query->lookup->done_as_is)
+               search = ISC_LIST_NEXT(oldlookup->origin, link);
+               if (search == NULL && oldlookup->done_as_is)
                        return (ISC_FALSE);
-               lookup = requeue_lookup(query->lookup, ISC_TRUE);
-               lookup->origin = search;
+               newlookup = requeue_lookup(oldlookup, ISC_TRUE);
+               newlookup->origin = search;
        }
-       cancel_lookup(query->lookup);
+       cancel_lookup(oldlookup);
        return (ISC_TRUE);
 }
 
@@ -2030,7 +2038,7 @@ insert_soa(dig_lookup_t *lookup) {
  * well as the query structures and buffer space for the replies.  If the
  * server list is empty, clone it from the system default list.
  */
-void
+isc_boolean_t
 setup_lookup(dig_lookup_t *lookup) {
        isc_result_t result;
        isc_uint32_t id;
@@ -2156,20 +2164,35 @@ setup_lookup(dig_lookup_t *lookup) {
                if (lookup->trace && lookup->trace_root) {
                        dns_name_clone(dns_rootname, lookup->name);
                } else {
+                       dns_fixedname_t fixed;
+                       dns_name_t *name;
+
+                       dns_fixedname_init(&fixed);
+                       name = dns_fixedname_name(&fixed);
                        len = strlen(lookup->textname);
                        isc_buffer_init(&b, lookup->textname, len);
                        isc_buffer_add(&b, len);
-                       result = dns_name_fromtext(lookup->name, &b,
-                                                  lookup->oname, 0,
-                                                  &lookup->namebuf);
-               }
-               if (result != ISC_R_SUCCESS) {
-                       dns_message_puttempname(lookup->sendmsg,
-                                               &lookup->name);
-                       dns_message_puttempname(lookup->sendmsg,
-                                               &lookup->oname);
-                       fatal("'%s' is not in legal name syntax (%s)",
-                             lookup->textname, isc_result_totext(result));
+                       result = dns_name_fromtext(name, &b, NULL, 0, NULL);
+                       if (result == ISC_R_SUCCESS &&
+                           !dns_name_isabsolute(name))
+                               result = dns_name_concatenate(name,
+                                                             lookup->oname,
+                                                             lookup->name,
+                                                             &lookup->namebuf);
+                       else if (result == ISC_R_SUCCESS)
+                               result = dns_name_copy(name, lookup->name,
+                                                      &lookup->namebuf);
+                       if (result != ISC_R_SUCCESS) {
+                               dns_message_puttempname(lookup->sendmsg,
+                                                       &lookup->name);
+                               dns_message_puttempname(lookup->sendmsg,
+                                                       &lookup->oname);
+                               if (result == DNS_R_NAMETOOLONG)
+                                       return (ISC_FALSE);
+                               fatal("'%s' is not in legal name syntax (%s)",
+                                     lookup->textname,
+                                     isc_result_totext(result));
+                       }
                }
                dns_message_puttempname(lookup->sendmsg, &lookup->oname);
        } else
@@ -2369,6 +2392,7 @@ setup_lookup(dig_lookup_t *lookup) {
                printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg,
                             ISC_TRUE);
        }
+       return (ISC_TRUE);
 }
 
 /*%
@@ -3489,7 +3513,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
        if (!l->doing_xfr || l->xfr_q == query) {
                if (msg->rcode == dns_rcode_nxdomain &&
                    (l->origin != NULL || l->need_search)) {
-                       if (!next_origin(query) || showsearch) {
+                       if (!next_origin(query->lookup) || showsearch) {
                                printmessage(query, msg, ISC_TRUE);
                                received(b->used, &sevent->address, query);
                        }
index 3a71ed6ccf4aa6184ad04de5a3eb494c89de78a5..d5c41c072f236194270e934c9e2616a513d948b0 100644 (file)
@@ -311,7 +311,7 @@ debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
 void
 check_result(isc_result_t result, const char *msg);
 
-void
+isc_boolean_t
 setup_lookup(dig_lookup_t *lookup);
 
 void
index f7196e02593d60ba70cfc0f0e4c1b77ecae3975a..fa89a679b18ef1bc419675b31a888544358e62a3 100644 (file)
@@ -51,6 +51,7 @@ JOURNALPRINT=$TOP/bin/tools/named-journalprint
 ARPANAME=$TOP/bin/tools/arpaname
 SAMPLE=$TOP/lib/export/samples/sample
 GENRANDOM=$TOP/bin/tools/genrandom
+NSLOOKUP=$TOP/bin/dig/nslookup
 
 RANDFILE=$TOP/bin/tests/system/random.data
 
@@ -58,15 +59,14 @@ RANDFILE=$TOP/bin/tests/system/random.data
 # load on the machine to make it unusable to other users.
 # v6synth
 SUBDIRS="acl additional allow_query addzone autosign builtin
-        cacheclean case checkconf checknames checkzone database dlv
-        dlvauto dlz dlzexternal dname dns64 dnssec ecdsa
-        emptyzones
-        filter-aaaa formerr
-        forward glue gost ixfr limits logfileconfig lwresd masterfile
-        masterformat metadata notify nsupdate pending pkcs11
-        resolver rndc rpz rrsetorder sortlist smartsign spf staticstub
-        stub tkey tsig tsiggss unknown upforwd views wildcard xfer
-        xferquota zero zonechecks"
+        cacheclean case checkconf checknames checkzone database
+        dlv dlvauto dlz dlzexternal dname dns64 dnssec ecdsa
+        emptyzones filter-aaaa formerr forward glue gost ixfr
+        limits logfileconfig lwresd masterfile masterformat metadata
+        notify nslookup nsupdate pending pkcs11 resolver rndc rpz
+        rrsetorder sortlist smartsign spf staticstub stub tkey
+        tsig tsiggss unknown upforwd views wildcard xfer xferquota
+        zero zonechecks"
 
 # Use the CONFIG_SHELL detected by configure for tests
 SHELL=@SHELL@
@@ -87,4 +87,4 @@ fi
 
 export NAMED LWRESD DIG NSUPDATE KEYGEN KEYFRLAB SIGNER KEYSIGNER KEYSETTOOL \
        PERL SUBDIRS RNDC CHECKZONE PK11GEN PK11LIST PK11DEL TESTSOCK6 \
-       JOURNALPRINT ARPANAME SAMPLE
+       JOURNALPRINT ARPANAME SAMPLE NSLOOKUP
diff --git a/bin/tests/system/nslookup/clean.sh b/bin/tests/system/nslookup/clean.sh
new file mode 100644 (file)
index 0000000..c43d9b8
--- /dev/null
@@ -0,0 +1,2 @@
+rm -f ns1/example.db
+rm -f nslookup.out*
diff --git a/bin/tests/system/nslookup/ns1/named.conf b/bin/tests/system/nslookup/ns1/named.conf
new file mode 100644 (file)
index 0000000..fc1fb51
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+controls { /* empty */ };
+
+options {
+       query-source address 10.53.0.1;
+       notify-source 10.53.0.1;
+       transfer-source 10.53.0.1;
+       port 5300;
+       pid-file "named.pid";
+       listen-on { 10.53.0.1; };
+       listen-on-v6 { none; };
+       recursion no;
+};
+
+zone "example" {
+       type master;
+       file "example.db";
+};
diff --git a/bin/tests/system/nslookup/setup.sh b/bin/tests/system/nslookup/setup.sh
new file mode 100644 (file)
index 0000000..092e580
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+#
+# Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+SYSTEMTESTTOP=..
+. $SYSTEMTESTTOP/conf.sh
+
+$SHELL ../genzone.sh 1 >ns1/example.db
diff --git a/bin/tests/system/nslookup/tests.sh b/bin/tests/system/nslookup/tests.sh
new file mode 100644 (file)
index 0000000..d77afd9
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+SYSTEMTESTTOP=..
+. $SYSTEMTESTTOP/conf.sh
+
+status=0
+n=0
+
+n=`expr $n + 1`
+echo "Check that domain names that are too big when applying a search list entry are handled cleanly ($n)"
+ret=0
+l=012345678901234567890123456789012345678901234567890123456789012
+t=0123456789012345678901234567890123456789012345678901234567890
+d=$l.$l.$l.$t
+$NSLOOKUP -port=5300 -domain=$d -type=soa example 10.53.0.1 > nslookup.out${n} || ret=1
+grep "origin = ns1.example" nslookup.out${n} > /dev/null || ret=1
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
+echo "I:exit status: $status"
+exit $status
+