Commit fd7f3a84 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2377] Defence of MasterLoader

Reject invalid parameters and invalid attempts to load twice.
parent 5ec0945e
...@@ -41,7 +41,8 @@ public: ...@@ -41,7 +41,8 @@ public:
options_(options), options_(options),
master_file_(master_file), master_file_(master_file),
initialized_(false), initialized_(false),
ok_(true) ok_(true),
complete_(false)
{} {}
void pushSource(const std::string& filename) { void pushSource(const std::string& filename) {
...@@ -58,6 +59,10 @@ public: ...@@ -58,6 +59,10 @@ public:
} }
bool loadIncremental(size_t count_limit) { bool loadIncremental(size_t count_limit) {
if (complete_) {
isc_throw(isc::InvalidOperation,
"Trying to load when already loaded");
}
if (!initialized_) { if (!initialized_) {
pushSource(master_file_); pushSource(master_file_);
initialized_ = true; initialized_ = true;
...@@ -161,6 +166,8 @@ private: ...@@ -161,6 +166,8 @@ private:
const std::string master_file_; const std::string master_file_;
bool initialized_; bool initialized_;
bool ok_; bool ok_;
public:
bool complete_;
}; };
MasterLoader::MasterLoader(const char* master_file, MasterLoader::MasterLoader(const char* master_file,
...@@ -170,6 +177,9 @@ MasterLoader::MasterLoader(const char* master_file, ...@@ -170,6 +177,9 @@ MasterLoader::MasterLoader(const char* master_file,
const AddRRCallback& add_callback, const AddRRCallback& add_callback,
Options options) Options options)
{ {
if (add_callback.empty()) {
isc_throw(isc::InvalidParameter, "Empty add RR callback");
}
impl_ = new MasterLoaderImpl(master_file, zone_origin, impl_ = new MasterLoaderImpl(master_file, zone_origin,
zone_class, callbacks, add_callback, options); zone_class, callbacks, add_callback, options);
} }
...@@ -180,7 +190,9 @@ MasterLoader::~MasterLoader() { ...@@ -180,7 +190,9 @@ MasterLoader::~MasterLoader() {
bool bool
MasterLoader::loadIncremental(size_t count_limit) { MasterLoader::loadIncremental(size_t count_limit) {
return (impl_->loadIncremental(count_limit)); bool result = impl_->loadIncremental(count_limit);
impl_->complete_ = result;
return (result);
} }
} // end namespace dns } // end namespace dns
......
...@@ -227,3 +227,19 @@ TEST_F(MasterLoaderTest, brokenZone) { ...@@ -227,3 +227,19 @@ TEST_F(MasterLoaderTest, brokenZone) {
} }
} }
} }
// Test the constructor rejects empty add callback.
TEST_F(MasterLoaderTest, emptyCallback) {
EXPECT_THROW(MasterLoader(TEST_DATA_SRCDIR "/example.org",
Name("example.org"), RRClass::IN(), callbacks_,
AddRRCallback()), isc::InvalidParameter);
}
// Check it throws when we try to load after loading was complete.
TEST_F(MasterLoaderTest, loadTwice) {
setLoader(TEST_DATA_SRCDIR "/example.org", Name("example.org."),
RRClass::IN(), MasterLoader::MANY_ERRORS);
loader_->load();
EXPECT_THROW(loader_->load(), isc::InvalidOperation);
}
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