BIND 10 trac2377, updated. fd7f3a84f391957a09996ab869d079b6fe53a9fd [2377] Defence of MasterLoader
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Dec 4 12:01:46 UTC 2012
The branch, trac2377 has been updated
via fd7f3a84f391957a09996ab869d079b6fe53a9fd (commit)
from 5ec0945ea8abd8ce3aa59aa851421269d9f807d4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit fd7f3a84f391957a09996ab869d079b6fe53a9fd
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Dec 4 13:01:20 2012 +0100
[2377] Defence of MasterLoader
Reject invalid parameters and invalid attempts to load twice.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_loader.cc | 16 ++++++++++++++--
src/lib/dns/tests/master_loader_unittest.cc | 16 ++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc
index 4b59cef..60a97d6 100644
--- a/src/lib/dns/master_loader.cc
+++ b/src/lib/dns/master_loader.cc
@@ -41,7 +41,8 @@ public:
options_(options),
master_file_(master_file),
initialized_(false),
- ok_(true)
+ ok_(true),
+ complete_(false)
{}
void pushSource(const std::string& filename) {
@@ -58,6 +59,10 @@ public:
}
bool loadIncremental(size_t count_limit) {
+ if (complete_) {
+ isc_throw(isc::InvalidOperation,
+ "Trying to load when already loaded");
+ }
if (!initialized_) {
pushSource(master_file_);
initialized_ = true;
@@ -161,6 +166,8 @@ private:
const std::string master_file_;
bool initialized_;
bool ok_;
+public:
+ bool complete_;
};
MasterLoader::MasterLoader(const char* master_file,
@@ -170,6 +177,9 @@ MasterLoader::MasterLoader(const char* master_file,
const AddRRCallback& add_callback,
Options options)
{
+ if (add_callback.empty()) {
+ isc_throw(isc::InvalidParameter, "Empty add RR callback");
+ }
impl_ = new MasterLoaderImpl(master_file, zone_origin,
zone_class, callbacks, add_callback, options);
}
@@ -180,7 +190,9 @@ MasterLoader::~MasterLoader() {
bool
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
diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc
index 58b347a..0264d48 100644
--- a/src/lib/dns/tests/master_loader_unittest.cc
+++ b/src/lib/dns/tests/master_loader_unittest.cc
@@ -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);
+}
More information about the bind10-changes
mailing list