BIND 10 trac2432, updated. 9cb41a2f06b35290e72eccc8246d8abf57f6e929 [2432] Throw during addRRset() if an rrset with the given class, type and name already exists

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Dec 26 05:18:46 UTC 2012


The branch, trac2432 has been updated
       via  9cb41a2f06b35290e72eccc8246d8abf57f6e929 (commit)
      from  7383457001cd2b6d78ec755f1cf20fa4529a43ab (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 9cb41a2f06b35290e72eccc8246d8abf57f6e929
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Dec 26 10:47:16 2012 +0530

    [2432] Throw during addRRset() if an rrset with the given class, type and name already exists

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

Summary of changes:
 src/lib/dns/rrset_collection.cc                |   11 +++++++++++
 src/lib/dns/rrset_collection.h                 |    4 +++-
 src/lib/dns/tests/rrset_collection_unittest.cc |    5 +++++
 3 files changed, 19 insertions(+), 1 deletion(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/rrset_collection.cc b/src/lib/dns/rrset_collection.cc
index 6cf2809..69e1cf4 100644
--- a/src/lib/dns/rrset_collection.cc
+++ b/src/lib/dns/rrset_collection.cc
@@ -16,8 +16,12 @@
 #include <dns/master_loader_callbacks.h>
 #include <dns/master_loader.h>
 
+#include <exceptions/exceptions.h>
+
 #include <boost/bind.hpp>
 
+using namespace isc;
+
 namespace isc {
 namespace dns {
 
@@ -41,6 +45,13 @@ void
 RRsetCollection::addRRset(RRsetPtr rrset) {
     const CollectionKey key(rrset->getClass(), rrset->getType(),
                             rrset->getName());
+    CollectionMap::const_iterator it = rrsets_.find(key);
+    if (it != rrsets_.end()) {
+        isc_throw(InvalidParameter,
+                  "RRset for " << rrset->getName() << "/" << rrset->getClass()
+                  << " with type " << rrset->getType() << " already exists");
+    }
+
     rrsets_.insert(std::pair<CollectionKey, RRsetPtr>(key, rrset));
 }
 
diff --git a/src/lib/dns/rrset_collection.h b/src/lib/dns/rrset_collection.h
index 37db6cc..b1998ae 100644
--- a/src/lib/dns/rrset_collection.h
+++ b/src/lib/dns/rrset_collection.h
@@ -50,7 +50,9 @@ public:
     /// \brief Add an RRset to the collection.
     ///
     /// Does not do any validation whether \c rrset belongs to a
-    /// particular zone or not.
+    /// particular zone or not. It throws an \c isc::InvalidParameter
+    /// exception if an rrset with the same class, type and name already
+    /// exists.
     void addRRset(isc::dns::RRsetPtr rrset);
 
     /// \brief Remove an RRset from the collection.
diff --git a/src/lib/dns/tests/rrset_collection_unittest.cc b/src/lib/dns/tests/rrset_collection_unittest.cc
index b222c45..29853e1 100644
--- a/src/lib/dns/tests/rrset_collection_unittest.cc
+++ b/src/lib/dns/tests/rrset_collection_unittest.cc
@@ -129,6 +129,11 @@ doAddAndRemove(RRsetCollection& collection, const RRClass& rrclass) {
     // The collection must not be empty.
     EXPECT_NE(collection.end(), collection.begin());
 
+    // Adding a duplicate RRset must throw.
+    EXPECT_THROW({
+        collection.addRRset(rrset);
+    }, isc::InvalidParameter);
+
     // Remove foo.example.org/A
     collection.removeRRset(Name("foo.example.org"), rrclass, RRType::A());
 



More information about the bind10-changes mailing list