Commit 6994c902 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

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

parent 1a488b6c
......@@ -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);
......
......@@ -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
......
......@@ -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));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment