BIND 10 trac2052, updated. c09a49cd3d1cd3498a7c7fb778abbe5485989e65 [2052] Fix code for comparisons of non-absolute label sequences

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jun 28 04:32:46 UTC 2012


The branch, trac2052 has been updated
       via  c09a49cd3d1cd3498a7c7fb778abbe5485989e65 (commit)
       via  491a0e2f9cd8a8c72bd9ae5c1650e523ca8afab9 (commit)
       via  02f0aa67d53e253855814e88e885cf19e6dfdf96 (commit)
      from  57c61f2f457ac99686706d05dda5cd39737c6bd0 (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 c09a49cd3d1cd3498a7c7fb778abbe5485989e65
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu Jun 28 09:52:11 2012 +0530

    [2052] Fix code for comparisons of non-absolute label sequences

commit 491a0e2f9cd8a8c72bd9ae5c1650e523ca8afab9
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu Jun 28 09:50:18 2012 +0530

    [2052] Fix documentation of partial_compare() for exceptions it can throw

commit 02f0aa67d53e253855814e88e885cf19e6dfdf96
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu Jun 28 09:49:35 2012 +0530

    [2052] Add more unittests for the behavior we expect

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

Summary of changes:
 src/lib/dns/labelsequence.cc                |    4 +-
 src/lib/dns/name.cc                         |   33 ++++++++--
 src/lib/dns/name.h                          |   13 +++-
 src/lib/dns/tests/labelsequence_unittest.cc |   87 ++++++++++++++++++++++++++-
 4 files changed, 126 insertions(+), 11 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc
index 817aa7c..76aee18 100644
--- a/src/lib/dns/labelsequence.cc
+++ b/src/lib/dns/labelsequence.cc
@@ -74,13 +74,15 @@ LabelSequence::equals(const LabelSequence& other, bool case_sensitive) const {
 NameComparisonResult
 LabelSequence::compare(const LabelSequence& other,
                        bool case_sensitive) const {
-    if ((!isAbsolute()) || (!other.isAbsolute())) {
+    if (isAbsolute() ^ other.isAbsolute()) {
         return (NameComparisonResult(0, 0, NameComparisonResult::NONE));
     }
 
     return (name_.partial_compare(other.name_,
                                   first_label_,
                                   other.first_label_,
+                                  last_label_,
+                                  other.last_label_,
                                   case_sensitive));
 }
 
diff --git a/src/lib/dns/name.cc b/src/lib/dns/name.cc
index 2864728..87bf41e 100644
--- a/src/lib/dns/name.cc
+++ b/src/lib/dns/name.cc
@@ -507,26 +507,33 @@ Name::toText(bool omit_final_dot) const {
 
 NameComparisonResult
 Name::compare(const Name& other) const {
-    return (partial_compare(other, 0, 0));
+    return (partial_compare(other, 0, 0, labelcount_, other.labelcount_));
 }
 
 NameComparisonResult
 Name::partial_compare(const Name& other,
                       unsigned int first_label,
                       unsigned int first_label_other,
+                      unsigned int last_label,
+                      unsigned int last_label_other,
                       bool case_sensitive) const {
     // Determine the relative ordering under the DNSSEC order relation of
     // 'this' and 'other', and also determine the hierarchical relationship
     // of the names.
 
+    if ((first_label > last_label) ||
+        (first_label_other > last_label_other)) {
+        isc_throw(BadValue, "Bad label index ranges were passed");
+    }
+
     if ((first_label > labelcount_) ||
         (first_label_other > other.labelcount_)) {
         isc_throw(BadValue, "Bad first label indices were passed");
     }
 
     unsigned int nlabels = 0;
-    int l1 = labelcount_ - first_label;
-    int l2 = other.labelcount_ - first_label_other;
+    int l1 = last_label - first_label;
+    int l2 = last_label_other - first_label_other;
     int ldiff = (int)l1 - (int)l2;
     unsigned int l = (ldiff < 0) ? l1 : l2;
 
@@ -558,16 +565,30 @@ Name::partial_compare(const Name& other,
             }
 
             if (chdiff != 0) {
-                return (NameComparisonResult(chdiff, nlabels,
-                                             NameComparisonResult::COMMONANCESTOR));
+                if ((nlabels == 0) &&
+                    ((last_label < labelcount_) ||
+                     (last_label_other < other.labelcount_))) {
+                    return (NameComparisonResult(chdiff, 0,
+                                                 NameComparisonResult::NONE));
+                } else {
+                    return (NameComparisonResult(chdiff, nlabels,
+                                                 NameComparisonResult::COMMONANCESTOR));
+                }
             }
             --count;
             ++pos1;
             ++pos2;
         }
         if (cdiff != 0) {
+            if ((nlabels == 0) &&
+                ((last_label < labelcount_) ||
+                 (last_label_other < other.labelcount_))) {
+                return (NameComparisonResult(cdiff, 0,
+                                             NameComparisonResult::NONE));
+            } else {
                 return (NameComparisonResult(cdiff, nlabels,
-                                         NameComparisonResult::COMMONANCESTOR));
+                                             NameComparisonResult::COMMONANCESTOR));
+            }
         }
         ++nlabels;
     }
diff --git a/src/lib/dns/name.h b/src/lib/dns/name.h
index 4e7564f..d6fb294 100644
--- a/src/lib/dns/name.h
+++ b/src/lib/dns/name.h
@@ -407,19 +407,26 @@ private:
     /// <code>Name</code> and <code>other</code> and returns the result
     /// in the form of a <code>NameComparisonResult</code> object.
     ///
-    /// This method never throws an exception.
+    /// This method can throw the BadValue exception if bad label
+    /// indices are passed.
     ///
     /// \param other the right-hand operand to compare against.
-    /// \param first_label the leftmost label of <code>Name</code> to
+    /// \param first_label the left-most label of <code>Name</code> to
     /// begin comparing from.
-    /// \param first_label_other the leftmost label of
+    /// \param first_label_other the left-most label of
     /// <code>other</code> to begin comparing from.
+    /// \param last_label the right-most label of <code>Name</code> to
+    /// end comparing at.
+    /// \param last_label_other the right-most label of
+    /// <code>other</code> to end comparing at.
     /// \param case_sensitive If true, comparison is case-insensitive
     /// \return a <code>NameComparisonResult</code> object representing the
     /// comparison result.
     NameComparisonResult partial_compare(const Name& other,
                                          unsigned int first_label,
                                          unsigned int first_label_other,
+                                         unsigned int last_label,
+                                         unsigned int last_label_other,
                                          bool case_sensitive = false) const;
 
 public:
diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc
index 7d26be7..73aa601 100644
--- a/src/lib/dns/tests/labelsequence_unittest.cc
+++ b/src/lib/dns/tests/labelsequence_unittest.cc
@@ -166,7 +166,7 @@ TEST_F(LabelSequenceTest, compare) {
     Name nc("g.f.e.d.c.example.org");
     LabelSequence lsc(nc);
 
-    // "g.f.e.d.c.example.org." and "b.example.org" (no hierarchy), case
+    // "g.f.e.d.c.example.org." and "b.example.org" (not absolute), case
     // in-sensitive
     lsb.stripRight(1);
     result = lsc.compare(lsb);
@@ -234,6 +234,91 @@ TEST_F(LabelSequenceTest, compare) {
     EXPECT_EQ(isc::dns::NameComparisonResult::EQUAL,
               result.getRelation());
     EXPECT_EQ(4, result.getCommonLabels());
+
+    Name nf("a.b.c.isc.example.org");
+    LabelSequence lsf(nf);
+    Name ng("w.x.y.isc.EXAMPLE.org");
+    LabelSequence lsg(ng);
+
+    // "a.b.c.isc.example.org." and "w.x.y.isc.EXAMPLE.org" (not
+    // absolute), case in-sensitive
+    lsg.stripRight(1);
+    result = lsg.compare(lsf);
+    EXPECT_EQ(isc::dns::NameComparisonResult::NONE,
+              result.getRelation());
+    EXPECT_EQ(0, result.getCommonLabels());
+
+    // "a.b.c.isc.example.org" (not absolute) and
+    // "w.x.y.isc.EXAMPLE.org" (not absolute), case in-sensitive
+    lsf.stripRight(1);
+    result = lsg.compare(lsf);
+    EXPECT_EQ(isc::dns::NameComparisonResult::COMMONANCESTOR,
+              result.getRelation());
+    EXPECT_EQ(3, result.getCommonLabels());
+
+    // "a.b.c.isc.example" (not absolute) and
+    // "w.x.y.isc.EXAMPLE" (not absolute), case in-sensitive
+    lsf.stripRight(1);
+    lsg.stripRight(1);
+    result = lsg.compare(lsf);
+    EXPECT_EQ(isc::dns::NameComparisonResult::COMMONANCESTOR,
+              result.getRelation());
+    EXPECT_EQ(2, result.getCommonLabels());
+
+    // "a.b.c" (not absolute) and
+    // "w.x.y" (not absolute), case in-sensitive
+    lsf.stripRight(2);
+    lsg.stripRight(2);
+    result = lsg.compare(lsf);
+    EXPECT_EQ(isc::dns::NameComparisonResult::NONE,
+              result.getRelation());
+    EXPECT_EQ(0, result.getCommonLabels());
+
+    Name nh("aexample.org");
+    LabelSequence lsh(nh);
+    Name ni("bexample.org");
+    LabelSequence lsi(ni);
+
+    // "aexample.org" (not absolute) and
+    // "bexample.org" (not absolute), case in-sensitive
+    lsh.stripRight(1);
+    lsi.stripRight(1);
+    result = lsh.compare(lsi);
+    EXPECT_EQ(isc::dns::NameComparisonResult::COMMONANCESTOR,
+              result.getRelation());
+    EXPECT_EQ(1, result.getCommonLabels());
+
+    // "aexample" (not absolute) and
+    // "bexample" (not absolute), case in-sensitive
+    lsh.stripRight(1);
+    lsi.stripRight(1);
+    result = lsh.compare(lsi);
+    EXPECT_EQ(isc::dns::NameComparisonResult::NONE,
+              result.getRelation());
+    EXPECT_EQ(0, result.getCommonLabels());
+
+    Name nj("example.org");
+    LabelSequence lsj(nj);
+    Name nk("example.org");
+    LabelSequence lsk(nk);
+
+    // "example.org" (not absolute) and
+    // "example.org" (not absolute), case in-sensitive
+    lsj.stripRight(1);
+    lsk.stripRight(1);
+    result = lsj.compare(lsk);
+    EXPECT_EQ(isc::dns::NameComparisonResult::EQUAL,
+              result.getRelation());
+    EXPECT_EQ(2, result.getCommonLabels());
+
+    // "example" (not absolute) and
+    // "example" (not absolute), case in-sensitive
+    lsj.stripRight(1);
+    lsk.stripRight(1);
+    result = lsj.compare(lsk);
+    EXPECT_EQ(isc::dns::NameComparisonResult::EQUAL,
+              result.getRelation());
+    EXPECT_EQ(1, result.getCommonLabels());
 }
 
 void



More information about the bind10-changes mailing list