]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
3154. [bug] Attempting to print an empty rdataset could trigger
authorEvan Hunt <each@isc.org>
Wed, 7 Sep 2011 19:11:14 +0000 (19:11 +0000)
committerEvan Hunt <each@isc.org>
Wed, 7 Sep 2011 19:11:14 +0000 (19:11 +0000)
an assert. [RT #25452]

CHANGES
lib/dns/masterdump.c
lib/dns/tests/master_test.c

diff --git a/CHANGES b/CHANGES
index 76af4116e28e15972b1dc495d514845a26637a80..20d8932c3960b7b87ff268fe2859ff886bd5db2f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+3154.  [bug]           Attempting to print an empty rdataset could trigger
+                       an assert. [RT #25452]
+
 3153.  [func]          Extend request-ixfr to zone level and remove the
                        side effect of forcing an AXFR. [RT #25156]
 
index 72d938d1cb9a4da2518ae0839dcc1ff6d65b0db4..e948922034f078de07da8014724218df38a1b7cc 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: masterdump.c,v 1.108 2011/06/08 22:13:50 each Exp $ */
+/* $Id: masterdump.c,v 1.109 2011/09/07 19:11:13 each Exp $ */
 
 /*! \file */
 
@@ -419,12 +419,11 @@ rdataset_totext(dns_rdataset_t *rdataset,
 
        rdataset->attributes |= DNS_RDATASETATTR_LOADORDER;
        result = dns_rdataset_first(rdataset);
-       REQUIRE(result == ISC_R_SUCCESS);
 
        current_ttl = ctx->current_ttl;
        current_ttl_valid = ctx->current_ttl_valid;
 
-       do {
+       while (result == ISC_R_SUCCESS) {
                column = 0;
 
                /*
@@ -550,7 +549,7 @@ rdataset_totext(dns_rdataset_t *rdataset,
 
                first = ISC_FALSE;
                result = dns_rdataset_next(rdataset);
-       } while (result == ISC_R_SUCCESS);
+       }
 
        if (result != ISC_R_NOMORE)
                return (result);
index baee4e1ef14959b821e01a28bdb7a796947221ab..99c1daa1cbe03fcbdcebd3c86f51cc61b855e164 100644 (file)
@@ -14,7 +14,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: master_test.c,v 1.5 2011/09/02 21:15:37 each Exp $ */
+/* $Id: master_test.c,v 1.6 2011/09/07 19:11:14 each Exp $ */
 
 /*! \file */
 
 #include <dns/cache.h>
 #include <dns/callbacks.h>
 #include <dns/master.h>
+#include <dns/masterdump.h>
 #include <dns/name.h>
 #include <dns/rdata.h>
+#include <dns/rdatalist.h>
 #include <dns/rdataset.h>
 
 #include "dnstest.h"
@@ -326,6 +328,50 @@ ATF_TC_BODY(master_leadingzero, tc) {
        dns_test_end();
 }
 
+ATF_TC(master_totext);
+ATF_TC_HEAD(master_totext, tc) {
+       atf_tc_set_md_var(tc, "descr", "masterfile totext tests");
+}
+ATF_TC_BODY(master_totext, tc) {
+       isc_result_t result;
+       dns_rdataset_t rdataset;
+       dns_rdatalist_t rdatalist;
+       isc_buffer_t target;
+       unsigned char buf[BIGBUFLEN];
+
+       UNUSED(tc);
+
+       result = dns_test_begin(NULL, ISC_FALSE);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       /* First, test with an empty rdataset */
+       rdatalist.rdclass = dns_rdataclass_in;
+       rdatalist.type = dns_rdatatype_none;
+       rdatalist.covers = dns_rdatatype_none;
+       rdatalist.ttl = 0;
+       ISC_LIST_INIT(rdatalist.rdata);
+       ISC_LINK_INIT(&rdatalist, link);
+
+       dns_rdataset_init(&rdataset);
+       result = dns_rdatalist_tordataset(&rdatalist, &rdataset);
+       ATF_CHECK_EQ(result, ISC_R_SUCCESS);
+
+       isc_buffer_init(&target, buf, BIGBUFLEN);
+       result = dns_master_rdatasettotext(dns_rootname,
+                                          &rdataset, &dns_master_style_debug,
+                                          &target);
+       ATF_CHECK_EQ(result, ISC_R_SUCCESS);
+       ATF_CHECK_EQ(isc_buffer_usedlength(&target), 0);
+
+       /*
+        * XXX: We will also need to add tests for dumping various
+        * rdata types, classes, etc, and comparing the results against
+        * known-good output.
+        */
+
+       dns_test_end();
+}
+
 /*
  * Main
  */
@@ -341,6 +387,7 @@ ATF_TP_ADD_TCS(tp) {
        ATF_TP_ADD_TC(tp, master_includefail);
        ATF_TP_ADD_TC(tp, master_blanklines);
        ATF_TP_ADD_TC(tp, master_leadingzero);
+       ATF_TP_ADD_TC(tp, master_totext);
 
        return (atf_no_error());
 }