BIND 10 trac2207, updated. 70aa7bfa24600d5492056c860838d94c9243c6aa [2207] Check the load action returns something
BIND 10 source code commits
bind10-changes at lists.isc.org
Sat Oct 13 09:48:43 UTC 2012
The branch, trac2207 has been updated
via 70aa7bfa24600d5492056c860838d94c9243c6aa (commit)
via 419020c407ac9f1ca0ab1f5a5c8b8b6219fb5d5b (commit)
from 58c41ea9cdb2df726b4b54015500acab3ae34040 (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 70aa7bfa24600d5492056c860838d94c9243c6aa
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Sat Oct 13 11:48:18 2012 +0200
[2207] Check the load action returns something
NULL makes no sense, so throw in that case.
commit 419020c407ac9f1ca0ab1f5a5c8b8b6219fb5d5b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Sat Oct 13 11:38:58 2012 +0200
[2207] Change signature of LoadAction
We allocate the ZoneData in the LoadAction, to match what happens in
ticket #2268 -- there's a function to load zone which allocates it
itself, we want to use it.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/memory/zone_reloader.cc | 9 +++---
src/lib/datasrc/memory/zone_reloader.h | 20 ++++++------
.../datasrc/tests/memory/zone_reloader_unittest.cc | 33 +++++++++++++++++---
3 files changed, 43 insertions(+), 19 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/zone_reloader.cc b/src/lib/datasrc/memory/zone_reloader.cc
index 67c6865..3027a70 100644
--- a/src/lib/datasrc/memory/zone_reloader.cc
+++ b/src/lib/datasrc/memory/zone_reloader.cc
@@ -27,12 +27,10 @@ namespace memory {
ZoneReloaderLocal::ZoneReloaderLocal(ZoneTableSegment* segment,
const LoadAction& load_action,
const InstallAction& install_action,
- const dns::Name& origin,
const dns::RRClass& rrclass) :
segment_(segment),
load_action_(load_action),
install_action_(install_action),
- origin_(origin),
rrclass_(rrclass),
zone_data_(NULL),
loaded_(false),
@@ -52,9 +50,12 @@ ZoneReloaderLocal::load() {
}
loaded_ = true;
- zone_data_ = ZoneData::create(segment_->getMemorySegment(), origin_);
+ zone_data_ = load_action_(segment_->getMemorySegment());
- load_action_(zone_data_);
+ if (zone_data_ == NULL) {
+ // Bug inside load_action_.
+ isc_throw(isc::Unexpected, "No data returned from load action");
+ }
data_ready_ = true;
}
diff --git a/src/lib/datasrc/memory/zone_reloader.h b/src/lib/datasrc/memory/zone_reloader.h
index 12e84dc..904b603 100644
--- a/src/lib/datasrc/memory/zone_reloader.h
+++ b/src/lib/datasrc/memory/zone_reloader.h
@@ -12,16 +12,17 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-#include <dns/name.h>
#include <dns/rrclass.h>
#include <boost/function.hpp>
namespace isc {
+// Forward declarations
+namespace util{
+class MemorySegment;
+}
namespace datasrc {
namespace memory {
-
-// Forward declarations
class ZoneData;
class ZoneTableSegment;
@@ -104,10 +105,12 @@ class ZoneSegmentID {};
/// \brief Callback to load data into the memory
///
-/// This is called with a clean (empty) zone data. The goal of the
-/// callback is to get the data for the zone from somewhere and put
-/// them into the passed ZoneData parameter.
-typedef boost::function<void(ZoneData*)> LoadAction;
+/// 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.
///
/// The goal of the callback is to take the zone data (contained in the
@@ -133,11 +136,9 @@ public:
/// \param segment The zone table segment to store the zone into.
/// \param load_action The callback used to load data.
/// \param install_action The callback used to install the loaded zone.
- /// \param origin The origin name of the zone.
/// \param rrclass The class of the zone.
ZoneReloaderLocal(ZoneTableSegment* segment, const LoadAction& load_action,
const InstallAction& install_action,
- const dns::Name& origin,
const dns::RRClass& rrclass);
/// \brief Destructor
~ZoneReloaderLocal();
@@ -169,7 +170,6 @@ private:
ZoneTableSegment* segment_;
LoadAction load_action_;
InstallAction install_action_;
- dns::Name origin_;
dns::RRClass rrclass_;
ZoneData* zone_data_;
// The load was performed
diff --git a/src/lib/datasrc/tests/memory/zone_reloader_unittest.cc b/src/lib/datasrc/tests/memory/zone_reloader_unittest.cc
index 4c71abd..ba9d5c2 100644
--- a/src/lib/datasrc/tests/memory/zone_reloader_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_reloader_unittest.cc
@@ -48,11 +48,12 @@ public:
_1),
bind(&ZoneReloaderLocalTest::installAction, this,
_1, _2),
- Name("example.org"), RRClass::IN())),
+ RRClass::IN())),
load_called_(false),
install_called_(false),
load_throw_(false),
- install_throw_(false)
+ install_throw_(false),
+ load_null_(false)
{}
void TearDown() {
// Release the reloader
@@ -67,15 +68,25 @@ protected:
bool install_called_;
bool load_throw_;
bool install_throw_;
+ bool load_null_;
private:
- void loadAction(ZoneData* data) {
- // Make sure we get something.
- EXPECT_NE(static_cast<const ZoneData*>(NULL), data);
+ ZoneData* loadAction(isc::util::MemorySegment& segment) {
+ // Make sure it is the correct segment passed. We know the
+ // exact instance, can compare pointers to them.
+ EXPECT_EQ(&segment_->getMemorySegment(), &segment);
// We got called
load_called_ = true;
if (load_throw_) {
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")));
}
ZoneData* installAction(const ZoneSegmentID&, ZoneSegment* segment) {
install_called_ = true;
@@ -234,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());
+}
+
}
More information about the bind10-changes
mailing list