BIND 10 trac2850_3, updated. 0d8512ac4efe7293ee5239d7202965971011be8d [2850] Check if ZoneTableHeader name exists in an existing segment

BIND 10 source code commits bind10-changes at lists.isc.org
Thu May 16 06:53:43 UTC 2013


The branch, trac2850_3 has been updated
       via  0d8512ac4efe7293ee5239d7202965971011be8d (commit)
      from  6de9f8bf01a42ec823e9db70b42ffa301c4a928f (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 0d8512ac4efe7293ee5239d7202965971011be8d
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu May 16 11:31:58 2013 +0530

    [2850] Check if ZoneTableHeader name exists in an existing segment

-----------------------------------------------------------------------

Summary of changes:
 .../datasrc/memory/zone_table_segment_mapped.cc    |   24 +++++++++++++++-----
 src/lib/datasrc/memory/zone_table_segment_mapped.h |    4 ++--
 2 files changed, 20 insertions(+), 8 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/zone_table_segment_mapped.cc b/src/lib/datasrc/memory/zone_table_segment_mapped.cc
index d2830fc..6770eb2 100644
--- a/src/lib/datasrc/memory/zone_table_segment_mapped.cc
+++ b/src/lib/datasrc/memory/zone_table_segment_mapped.cc
@@ -53,7 +53,7 @@ ZoneTableSegmentMapped::getImplType() const {
 
 bool
 ZoneTableSegmentMapped::processChecksum(MemorySegmentMapped& segment,
-                                        bool create,
+                                        bool create, bool has_allocations,
                                         std::string& error_msg)
 {
     const MemorySegment::NamedAddressResult result =
@@ -80,9 +80,9 @@ ZoneTableSegmentMapped::processChecksum(MemorySegmentMapped& segment,
             }
         }
     } else {
-        if ((!create) && (!segment.allMemoryDeallocated())) {
+        if ((!create) && has_allocations) {
             // If we are resetting in READ_WRITE mode, and some memory
-            // was already allocated but there is no checksum, that
+            // was already allocated but there is no checksum name, that
             // indicates that the segment is corrupted.
             error_msg = "Existing segment is missing a checksum name";
             return (false);
@@ -106,7 +106,7 @@ ZoneTableSegmentMapped::processChecksum(MemorySegmentMapped& segment,
 
 bool
 ZoneTableSegmentMapped::processHeader(MemorySegmentMapped& segment,
-                                      bool create,
+                                      bool create, bool has_allocations,
                                       std::string& error_msg)
 {
     const MemorySegment::NamedAddressResult result =
@@ -121,6 +121,14 @@ ZoneTableSegmentMapped::processHeader(MemorySegmentMapped& segment,
             assert(result.second);
         }
     } else {
+        if ((!create) && has_allocations) {
+            // If we are resetting in READ_WRITE mode, and some memory
+            // was already allocated but there is no header name, that
+            // indicates that the segment is corrupted.
+            error_msg = "Existing segment is missing a ZoneTableHeader name";
+            return (false);
+        }
+
         void* ptr = NULL;
         while (!ptr) {
             try {
@@ -168,9 +176,13 @@ ZoneTableSegmentMapped::openReadWrite(const std::string& filename,
     std::auto_ptr<MemorySegmentMapped> segment
         (new MemorySegmentMapped(filename, mode));
 
+    // This flag is used inside processCheckSum() and processHeader(),
+    // and must be initialized before we make any further allocations.
+    const bool has_allocations = !segment->allMemoryDeallocated();
+
     std::string error_msg;
-    if ((!processChecksum(*segment, create, error_msg)) ||
-        (!processHeader(*segment, create, error_msg))) {
+    if ((!processChecksum(*segment, create, has_allocations, error_msg)) ||
+        (!processHeader(*segment, create, has_allocations, error_msg))) {
          if (mem_sgmt_) {
               isc_throw(ResetFailed,
                         "Error in resetting zone table segment to use "
diff --git a/src/lib/datasrc/memory/zone_table_segment_mapped.h b/src/lib/datasrc/memory/zone_table_segment_mapped.h
index 93bd7fa..616979a 100644
--- a/src/lib/datasrc/memory/zone_table_segment_mapped.h
+++ b/src/lib/datasrc/memory/zone_table_segment_mapped.h
@@ -122,9 +122,9 @@ private:
     void sync();
 
     bool processChecksum(isc::util::MemorySegmentMapped& segment, bool create,
-                         std::string& error_msg);
+                         bool has_allocations, std::string& error_msg);
     bool processHeader(isc::util::MemorySegmentMapped& segment, bool create,
-                       std::string& error_msg);
+                       bool has_allocations, std::string& error_msg);
 
     isc::util::MemorySegmentMapped* openReadWrite(const std::string& filename,
                                                   bool create);



More information about the bind10-changes mailing list