Browse Source

[2470] check and reject ampty add-RRset callback.

JINMEI Tatuya 12 years ago
parent
commit
0e2ef3c723
3 changed files with 15 additions and 1 deletions
  1. 7 1
      src/lib/dns/rrcollator.cc
  2. 3 0
      src/lib/dns/rrcollator.h
  3. 5 0
      src/lib/dns/tests/rrcollator_unittest.cc

+ 7 - 1
src/lib/dns/rrcollator.cc

@@ -12,6 +12,8 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+#include <exceptions/exceptions.h>
+
 #include <dns/name.h>
 #include <dns/rdataclass.h>
 #include <dns/rrcollator.h>
@@ -34,7 +36,11 @@ public:
     Impl(const AddRRsetCallback& callback,
          const MasterLoaderCallbacks& issue_callback) :
         callback_(callback), issue_callback_(issue_callback)
-    {}
+    {
+        if (!callback_) {
+            isc_throw(InvalidParameter, "Empty add RRset callback");
+        }
+    }
 
     void addRR(const Name& name, const RRClass& rrclass,
                const RRType& rrtype, const RRTTL& rrttl,

+ 3 - 0
src/lib/dns/rrcollator.h

@@ -63,6 +63,8 @@ public:
 
     /// \brief Constructor.
     ///
+    /// \c callback must not be an empty functor.
+    ///
     /// If the optional issue_callback parameter is given, it will be used
     /// to report any errors and non fatal warnings found in the collator's
     /// operation.  By default special callbacks that do nothing are used.
@@ -74,6 +76,7 @@ public:
     /// "<unknown source>" for the source name and the line number of 0 via
     /// the callback.
     ///
+    /// \throw isc::InvalidParameter Empty RRset callback is given.
     /// \throw std::bad_alloc Internal memory allocation fails.  This should
     /// be very rare.
     ///

+ 5 - 0
src/lib/dns/tests/rrcollator_unittest.cc

@@ -237,6 +237,11 @@ TEST_F(RRCollatorTest, throwFromCallback) {
     checkRRset(origin_, rrclass_, RRType::A(), rrttl_, rdatas_);
 }
 
+TEST_F(RRCollatorTest, emptyCallback) {
+    const AddRRsetCallback empty_callback;
+    EXPECT_THROW(RRCollator collator(empty_callback), isc::InvalidParameter);
+}
+
 TEST_F(RRCollatorTest, withMasterLoader) {
     // Test a simple case with MasterLoader.  There shouldn't be anything
     // special, but that's the mainly intended usage of the collator, so we