Parcourir la source

[2219] cover a minor case: zone finder's getOrigin() with non absolute label.

JINMEI Tatuya il y a 12 ans
Parent
commit
01244a662e

+ 23 - 0
src/lib/datasrc/memory/zone_finder.cc

@@ -768,6 +768,29 @@ InMemoryZoneFinder::findNSEC3(const isc::dns::Name& name, bool recursive) {
               << getClass());
 }
 
+Name
+InMemoryZoneFinder::getOrigin() const {
+    size_t data_len;
+    const uint8_t* data;
+
+    // Normally the label sequence of the origin node should be absolute,
+    // in which case we can simply generate the origin name from the labels.
+    const LabelSequence node_labels = zone_data_.getOriginNode()->getLabels();
+    if (node_labels.isAbsolute()) {
+        data = node_labels.getData(&data_len);
+    } else {
+        // If and when we allow non absolute label at the origin (e.g. for
+        // the convenience of out-of-zone glue handling), we first need to
+        // construct the absolute label sequence and then construct the name.
+        uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
+        const LabelSequence name_labels =
+            zone_data_.getOriginNode()->getAbsoluteLabels(labels_buf);
+        data = name_labels.getData(&data_len);
+    }
+    util::InputBuffer buffer(data, data_len);
+    return (Name(buffer));
+}
+
 } // namespace memory
 } // namespace datasrc
 } // namespace isc

+ 1 - 3
src/lib/datasrc/memory/zone_finder.h

@@ -99,9 +99,7 @@ public:
     findNSEC3(const isc::dns::Name& name, bool recursive);
 
     /// \brief Returns the origin of the zone.
-    virtual isc::dns::Name getOrigin() const {
-        return (zone_data_.getOriginNode()->getName());
-    }
+    virtual isc::dns::Name getOrigin() const;
 
     /// \brief Returns the RR class of the zone.
     virtual isc::dns::RRClass getClass() const {

+ 7 - 0
src/lib/datasrc/tests/memory/zone_finder_unittest.cc

@@ -557,6 +557,13 @@ public:
  */
 TEST_F(InMemoryZoneFinderTest, constructor) {
     ASSERT_EQ(origin_, zone_finder_.getOrigin());
+
+    // Some unusual (abnormal case): if we add a super domain name of the
+    // zone somehow, the label of the origin node won't be absolute.
+    // getOrigin() should still be the correct one.
+    ZoneNode *node;
+    zone_data_->insertName(mem_sgmt_, Name("org"), &node);
+    ASSERT_EQ(origin_, zone_finder_.getOrigin());
 }
 
 TEST_F(InMemoryZoneFinderTest, findCNAME) {