Commit 70aa7bfa authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2207] Check the load action returns something

NULL makes no sense, so throw in that case.
parent 419020c4
......@@ -52,6 +52,11 @@ ZoneReloaderLocal::load() {
zone_data_ = load_action_(segment_->getMemorySegment());
if (zone_data_ == NULL) {
// Bug inside load_action_.
isc_throw(isc::Unexpected, "No data returned from load action");
}
data_ready_ = true;
}
......
......@@ -108,6 +108,8 @@ class ZoneSegmentID {};
/// This callback should create new ZoneData (allocated from the passed
/// memory segment) and fill it with relevant loaded data. The caller
/// of the callback takes ownership of the ZoneData.
///
/// It must not return NULL.
typedef boost::function<ZoneData*(util::MemorySegment&)> LoadAction;
/// \brief Install the zone somewhere.
///
......
......@@ -52,7 +52,8 @@ public:
load_called_(false),
install_called_(false),
load_throw_(false),
install_throw_(false)
install_throw_(false),
load_null_(false)
{}
void TearDown() {
// Release the reloader
......@@ -67,6 +68,7 @@ protected:
bool install_called_;
bool load_throw_;
bool install_throw_;
bool load_null_;
private:
ZoneData* loadAction(isc::util::MemorySegment& segment) {
// Make sure it is the correct segment passed. We know the
......@@ -78,6 +80,10 @@ private:
throw TestException();
}
if (load_null_) {
// Be nasty to the caller and return NULL, which is forbidden
return (NULL);
}
// Create a new zone data. It may be empty for our tests, nothing
// goes inside.
return (ZoneData::create(segment, Name("example.org")));
......@@ -239,4 +245,16 @@ TEST_F(ZoneReloaderLocalTest, installThrows) {
EXPECT_NO_THROW(reloader_->cleanup());
}
// Check the reloader defends itsefl when load action returns NULL
TEST_F(ZoneReloaderLocalTest, loadNull) {
load_null_ = true;
EXPECT_THROW(reloader_->load(), isc::Unexpected);
// We can't install that
EXPECT_THROW(reloader_->install(), isc::Unexpected);
// It should be possible to clean up safely
EXPECT_NO_THROW(reloader_->cleanup());
}
}
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