BIND 10 trac2053, updated. 23ae3c2bbdf1a9f22c124aeeac2ac3c1692deb76 [2053] Add checks with long label sequences

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Jul 4 05:26:58 UTC 2012


The branch, trac2053 has been updated
       via  23ae3c2bbdf1a9f22c124aeeac2ac3c1692deb76 (commit)
       via  3a1e804a487e5406ec11bd62ae4ed76a15c49970 (commit)
       via  d83d9fe8ef6beaebe03fd486ca9b203aa60b4891 (commit)
       via  fdcc93e8ee07547f9fe86d56999b9ed5b5ac78d2 (commit)
       via  09d780b7f01d9f94e0da683ddc2539f2f5b03d1a (commit)
       via  e20691f8d713bb257033db96533fff11f5872752 (commit)
       via  15364a524a668d37a4fd63427f4eda5fd79e60e6 (commit)
       via  6c78bb408db659d97a4af548da504175a22bfabe (commit)
      from  b945fd1c9eee6fd70016a24b547426e1633faf8f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 23ae3c2bbdf1a9f22c124aeeac2ac3c1692deb76
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 4 10:36:54 2012 +0530

    [2053] Add checks with long label sequences

commit 3a1e804a487e5406ec11bd62ae4ed76a15c49970
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 4 10:17:17 2012 +0530

    [2053] Fix output of right-stripped label sequences

commit d83d9fe8ef6beaebe03fd486ca9b203aa60b4891
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 4 09:58:18 2012 +0530

    [2053] Remove obsolete comment

commit fdcc93e8ee07547f9fe86d56999b9ed5b5ac78d2
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 4 09:48:35 2012 +0530

    [2053] Rewrite code to handle the root name

commit 09d780b7f01d9f94e0da683ddc2539f2f5b03d1a
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 4 09:29:18 2012 +0530

    [2053] Use methods on Name instead of accessing member variables directly

commit e20691f8d713bb257033db96533fff11f5872752
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 4 09:25:49 2012 +0530

    [2053] Remove checks that are no longer necessary

commit 15364a524a668d37a4fd63427f4eda5fd79e60e6
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 4 09:24:48 2012 +0530

    [2053] Remove loop to locate the start point

commit 6c78bb408db659d97a4af548da504175a22bfabe
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 4 09:18:17 2012 +0530

    [2053] Make LabelSequence::toText(bool) a private method

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/labelsequence.cc                |   41 ++++++-----------
 src/lib/dns/labelsequence.h                 |   27 ++++++------
 src/lib/dns/tests/labelsequence_unittest.cc |   63 +++++++++++++++++++++++++--
 3 files changed, 86 insertions(+), 45 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc
index c1db000..dd5b2c8 100644
--- a/src/lib/dns/labelsequence.cc
+++ b/src/lib/dns/labelsequence.cc
@@ -114,21 +114,8 @@ LabelSequence::getHash(bool case_sensitive) const {
 
 std::string
 LabelSequence::toText(bool omit_final_dot) const {
-    if ((first_label_ > name_.labelcount_) ||
-        (last_label_ > name_.labelcount_) ||
-        (first_label_ > last_label_)) {
-        isc_throw(BadValue, "Bad first label indices were passed");
-    }
-
-    if (name_.length_ == 1) {
-        //
-        // Special handling for the root label.  We ignore omit_final_dot.
-        //
-        assert(name_.labelcount_ == 1 && name_.ndata_[0] == '\0');
-        return (".");
-    }
-
-    Name::NameString::const_iterator np = name_.ndata_.begin();
+    Name::NameString::const_iterator np = name_.ndata_.begin() +
+        name_.offsets_[first_label_];
     const Name::NameString::const_iterator np_end = name_.ndata_.end();
     // use for integrity check
     unsigned int labels = last_label_ - first_label_;
@@ -138,29 +125,27 @@ LabelSequence::toText(bool omit_final_dot) const {
     // result string: it will roughly have the same length as the wire format
     // name data.  reserve that length to minimize reallocation.
     std::string result;
-    result.reserve(name_.length_);
-
-    for (unsigned int i = 0; i < first_label_; i++) {
-        count = *np++;
-        np += count;
-    }
+    result.reserve(name_.getLength());
 
     while (np != np_end) {
+        if (labels == 0) {
+            count = 0;
+            break;
+        }
+
         labels--;
         count = *np++;
 
         if (count == 0) {
-            if (!omit_final_dot) {
+            // We've reached the "final dot".  If we've not dumped any
+            // character, the entire label sequence is the root name.
+            // In that case we don't omit the final dot.
+            if (!omit_final_dot || result.empty()) {
                 result.push_back('.');
             }
             break;
         }
 
-        if (labels == 0) {
-            count = 0;
-            break;
-        }
-
         if (count <= Name::MAX_LABELLEN) {
             assert(np_end - np >= count);
 
@@ -203,7 +188,7 @@ LabelSequence::toText(bool omit_final_dot) const {
     }
 
     assert(labels == 0);
-    assert(count == 0);         // a valid name must end with a 'dot'.
+    assert(count == 0);
 
     return (result);
 }
diff --git a/src/lib/dns/labelsequence.h b/src/lib/dns/labelsequence.h
index 374e6c4..7d8827e 100644
--- a/src/lib/dns/labelsequence.h
+++ b/src/lib/dns/labelsequence.h
@@ -41,6 +41,9 @@ namespace dns {
 /// data of the associated Name object).
 ///
 class LabelSequence {
+    // Name calls the private toText(bool) method of LabelSequence.
+    friend std::string Name::toText(bool) const;
+
 public:
     /// \brief Constructs a LabelSequence for the given name
     ///
@@ -127,7 +130,7 @@ public:
     ///
     /// This method returns a <code>std::string</code> object representing the
     /// LabelSequence as a string.  The returned string ends with a dot
-    /// '.' if <code>omit_final_dot</code> is <code>false</code>.
+    /// '.' if the label sequence is absolute.
     ///
     /// This function assumes the underlying name is in proper
     /// uncompressed wire format.  If it finds an unexpected label
@@ -136,26 +139,22 @@ public:
     /// allocation for the result string fails, a corresponding standard
     /// exception will be thrown.
     //
-    /// \param omit_final_dot whether to omit the trailing dot in the output.
     /// \return a string representation of the <code>LabelSequence</code>.
-    std::string toText(bool omit_final_dot) const;
+    std::string toText() const;
 
+private:
     /// \brief Convert the LabelSequence to a string.
     ///
-    /// This method returns a <code>std::string</code> object representing the
-    /// LabelSequence as a string.  The returned string ends with a dot
-    /// '.' if the label sequence is absolute.
+    /// This method is a version of the zero-argument toText() method,
+    /// that accepts a <code>omit_final_dot</code> argument. The
+    /// returned string ends with a dot '.' if
+    /// <code>omit_final_dot</code> is <code>false</code>.
     ///
-    /// This function assumes the underlying name is in proper
-    /// uncompressed wire format.  If it finds an unexpected label
-    /// character including compression pointer, an exception of class
-    /// \c BadLabelType will be thrown.  In addition, if resource
-    /// allocation for the result string fails, a corresponding standard
-    /// exception will be thrown.
-    //
+    /// \param omit_final_dot whether to omit the trailing dot in the output.
     /// \return a string representation of the <code>LabelSequence</code>.
-    std::string toText() const;
+    std::string toText(bool omit_final_dot) const;
 
+public:
     /// \brief Calculate a simple hash for the label sequence.
     ///
     /// This method calculates a hash value for the label sequence as binary
diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc
index be26246..cd4403e 100644
--- a/src/lib/dns/tests/labelsequence_unittest.cc
+++ b/src/lib/dns/tests/labelsequence_unittest.cc
@@ -293,6 +293,8 @@ TEST_F(LabelSequenceTest, isAbsolute) {
 }
 
 TEST_F(LabelSequenceTest, toText) {
+    EXPECT_EQ(".", ls7.toText());
+
     EXPECT_EQ("example.org.", ls1.toText());
     ls1.stripLeft(1);
     EXPECT_EQ("org.", ls1.toText());
@@ -301,16 +303,71 @@ TEST_F(LabelSequenceTest, toText) {
 
     EXPECT_EQ("example.com.", ls2.toText());
     ls2.stripRight(1);
-    EXPECT_EQ("example", ls2.toText());
+    EXPECT_EQ("example.com", ls2.toText());
     ls2.stripRight(1);
-    EXPECT_EQ("", ls2.toText());
+    EXPECT_EQ("example", ls2.toText());
 
     EXPECT_EQ("foo.example.org.bar.", ls8.toText());
     ls8.stripRight(2);
-    EXPECT_EQ("foo.example", ls8.toText());
+    EXPECT_EQ("foo.example.org", ls8.toText());
 
     EXPECT_EQ(".", ls7.toText());
     EXPECT_THROW(ls7.stripLeft(1), isc::OutOfRange);
+
+    Name n_long1("012345678901234567890123456789"
+                 "012345678901234567890123456789012."
+                 "012345678901234567890123456789"
+                 "012345678901234567890123456789012."
+                 "012345678901234567890123456789"
+                 "012345678901234567890123456789012."
+                 "012345678901234567890123456789"
+                 "0123456789012345678901234567890");
+    LabelSequence ls_long1(n_long1);
+
+    EXPECT_EQ("012345678901234567890123456789"
+              "012345678901234567890123456789012."
+              "012345678901234567890123456789"
+              "012345678901234567890123456789012."
+              "012345678901234567890123456789"
+              "012345678901234567890123456789012."
+              "012345678901234567890123456789"
+              "0123456789012345678901234567890.", ls_long1.toText());
+    ls_long1.stripRight(1);
+    EXPECT_EQ("012345678901234567890123456789"
+              "012345678901234567890123456789012."
+              "012345678901234567890123456789"
+              "012345678901234567890123456789012."
+              "012345678901234567890123456789"
+              "012345678901234567890123456789012."
+              "012345678901234567890123456789"
+              "0123456789012345678901234567890", ls_long1.toText());
+
+    Name n_long2("0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+                 "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+                 "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+                 "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+                 "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+                 "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+                 "0.1.2.3.4.5.6");
+    LabelSequence ls_long2(n_long2);
+
+    EXPECT_EQ("0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.", ls_long2.toText());
+    ls_long2.stripRight(1);
+    EXPECT_EQ("0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9."
+              "0.1.2.3.4.5.6", ls_long2.toText());
+    ls_long2.stripRight(125);
+    EXPECT_EQ("0.1", ls_long2.toText());
 }
 
 // The following are test data used in the getHash test below.  Normally



More information about the bind10-changes mailing list