]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2504] Fix getClosestNSEC() when tree.find() results in SUBDOMAIN
authorMukund Sivaraman <muks@isc.org>
Thu, 6 Dec 2012 10:28:25 +0000 (15:58 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 6 Dec 2012 10:28:30 +0000 (15:58 +0530)
When tree.find() results in SUBDOMAIN, the node_path's top contains the
previous node.  Calling previousNode() yet again will return its
further previous node.

src/lib/datasrc/memory/zone_finder.cc

index 4240c21d6304a0123cd65fcf716dfecf44fdd110..7f57d8ede20fcf2916bf96e41bd288b2e750e459 100644 (file)
@@ -305,8 +305,16 @@ getClosestNSEC(const ZoneData& zone_data,
     }
 
     const ZoneNode* prev_node;
-    while ((prev_node = zone_data.getZoneTree().previousNode(node_path))
-           != NULL) {
+    if (node_path.getLastComparisonResult().getRelation() ==
+        NameComparisonResult::SUBDOMAIN) {
+         // In case the search ended as a sub-domain, the previous node
+         // is already at the top of node_path.
+         prev_node = node_path.getLastComparedNode();
+    } else {
+         prev_node = zone_data.getZoneTree().previousNode(node_path);
+    }
+
+    while (prev_node != NULL) {
         if (!prev_node->isEmpty()) {
             const RdataSet* found =
                 RdataSet::find(prev_node->getData(), RRType::NSEC());
@@ -314,6 +322,7 @@ getClosestNSEC(const ZoneData& zone_data,
                 return (ConstNodeRRset(prev_node, found));
             }
         }
+        prev_node = zone_data.getZoneTree().previousNode(node_path);
     }
     // This must be impossible and should be an internal bug.
     // See the description at the method declaration.