From: Mukund Sivaraman Date: Wed, 26 Dec 2012 05:17:16 +0000 (+0530) Subject: [2432] Throw during addRRset() if an rrset with the given class, type and name alread... X-Git-Tag: bind10-1.0.0-rc-release~155 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9cb41a2f06b35290e72eccc8246d8abf57f6e929;p=thirdparty%2Fkea.git [2432] Throw during addRRset() if an rrset with the given class, type and name already exists --- diff --git a/src/lib/dns/rrset_collection.cc b/src/lib/dns/rrset_collection.cc index 6cf280902d..69e1cf4b9c 100644 --- a/src/lib/dns/rrset_collection.cc +++ b/src/lib/dns/rrset_collection.cc @@ -16,8 +16,12 @@ #include #include +#include + #include +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(key, rrset)); } diff --git a/src/lib/dns/rrset_collection.h b/src/lib/dns/rrset_collection.h index 37db6cca4f..b1998ae4d8 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 b222c45b82..29853e12bc 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());