Browse Source

[2905] explicitly reject adding empty zone data directly, for safety.

JINMEI Tatuya 12 years ago
parent
commit
6994c90205

+ 4 - 2
src/lib/datasrc/memory/zone_table.cc

@@ -18,6 +18,8 @@
 #include <datasrc/memory/segment_object_holder.h>
 #include <datasrc/memory/logger.h>
 
+#include <exceptions/exceptions.h>
+
 #include <util/memory_segment.h>
 
 #include <dns/name.h>
@@ -86,8 +88,8 @@ ZoneTable::addZone(util::MemorySegment& mem_sgmt, RRClass zone_class,
     LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_ADD_ZONE).
         arg(zone_name).arg(rrclass_);
 
-    if (content == NULL) {
-        isc_throw(isc::BadValue, "Zone content must not be NULL");
+    if (!content || content->isEmpty()) {
+        isc_throw(InvalidParameter, "Zone content must not be NULL or empty");
     }
     SegmentObjectHolder<ZoneData, RRClass> holder(mem_sgmt, zone_class);
     holder.set(content);

+ 4 - 3
src/lib/datasrc/memory/zone_table.h

@@ -167,6 +167,7 @@ public:
     /// accordingly.  On successful return, this method ensures there's no
     /// address relocation.
     ///
+    /// \throw InvalidParameter content is NULL or empty.
     /// \throw util::MemorySegmentGrown The memory segment has grown, possibly
     ///     relocating data.
     /// \throw std::bad_alloc Internal resource allocation fails.
@@ -178,9 +179,9 @@ public:
     /// \param zone_class The RR class of the zone.  It must be the RR class
     ///     that is supposed to be associated to the zone table.
     /// \param content This one should hold the zone content (the ZoneData).
-    ///     The ownership is passed onto the zone table. Must not be null.
-    ///     Must correspond to the name and class and must be allocated from
-    ///     mem_sgmt.
+    ///     The ownership is passed onto the zone table. Must not be null or
+    ///     empty. Must correspond to the name and class and must be allocated
+    ///     from mem_sgmt.
     /// \return \c result::SUCCESS If the zone is successfully
     ///     added to the zone table.
     /// \return \c result::EXIST The zone table already contained

+ 9 - 1
src/lib/datasrc/tests/memory/zone_table_unittest.cc

@@ -75,9 +75,17 @@ TEST_F(ZoneTableTest, addZone) {
 
     // It doesn't accept empty (NULL) zones
     EXPECT_THROW(zone_table->addZone(mem_sgmt_, zclass_, zname1, NULL),
-                 isc::BadValue);
+                 isc::InvalidParameter);
     EXPECT_EQ(0, zone_table->getZoneCount()); // count is still 0
 
+    // or an empty zone
+    SegmentObjectHolder<ZoneData, RRClass> holder_empty(
+        mem_sgmt_, zclass_);
+    holder_empty.set(ZoneData::create(mem_sgmt_));
+    EXPECT_THROW(zone_table->addZone(mem_sgmt_, zclass_, zname1,
+                                     holder_empty.get()),
+                 isc::InvalidParameter);
+
     SegmentObjectHolder<ZoneData, RRClass> holder1(
         mem_sgmt_, zclass_);
     holder1.set(ZoneData::create(mem_sgmt_, zname1));