Browse Source

[2435] Don't throw in case of out of zone queries

Mukund Sivaraman 12 years ago
parent
commit
5e3bc4cf78
2 changed files with 16 additions and 5 deletions
  1. 11 5
      src/lib/datasrc/rrset_collection.cc
  2. 5 0
      src/lib/datasrc/tests/database_unittest.cc

+ 11 - 5
src/lib/datasrc/rrset_collection.cc

@@ -35,11 +35,17 @@ RRsetCollection::find(const isc::dns::Name& name,
     }
 
     ZoneFinder& finder = updater_->getFinder();
-    ZoneFinderContextPtr result =
-        finder.find(name, rrtype,
-                    ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK);
-
-    return (result->rrset);
+    try {
+        ZoneFinderContextPtr result =
+            finder.find(name, rrtype,
+                        ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK);
+        return (result->rrset);
+    } catch (const OutOfZone&) {
+        // As RRsetCollection is an arbitrary set of RRsets, in case the
+        // searched name is out of zone, we return nothing instead of
+        // propagating the exception.
+        return (ConstRRsetPtr());
+    }
 }
 
 RRsetCollectionBase::IterPtr

+ 5 - 0
src/lib/datasrc/tests/database_unittest.cc

@@ -4198,6 +4198,11 @@ TYPED_TEST(RRsetCollectionTest, find) {
     rrset = this->collection.find(Name("www.example.org"), RRClass::CH(),
                                   RRType::AAAA());
     EXPECT_FALSE(rrset);
+
+    // Out of zone find()s must not throw.
+    rrset = this->collection.find(Name("www.example.com"), this->qclass_,
+                                  RRType::A());
+    EXPECT_FALSE(rrset);
 }
 
 TYPED_TEST(RRsetCollectionTest, iteratorTest) {