This is an automated email from the ASF dual-hosted git repository.

eze pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new 6dedd1e810 Fix host.db load failure due to incorrect object_version 
compatibility check (#12395)
6dedd1e810 is described below

commit 6dedd1e810170e1f98768efee7c89d4a9a1c9d2a
Author: Katsutoshi Ikenoya <[email protected]>
AuthorDate: Fri Sep 5 04:52:46 2025 +0900

    Fix host.db load failure due to incorrect object_version compatibility 
check (#12395)
    
    * Fix host.db load failure due to incorrect object_version compatibility 
check
    
    * Fix unintended initialization of member variables in 
HostDBInfo::unmarshall
---
 iocore/hostdb/I_HostDBProcessor.h | 29 +++++++++++++++++++++++------
 iocore/hostdb/RefCountCache.cc    |  2 +-
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/iocore/hostdb/I_HostDBProcessor.h 
b/iocore/hostdb/I_HostDBProcessor.h
index 0be0a81b4a..a44f2c8572 100644
--- a/iocore/hostdb/I_HostDBProcessor.h
+++ b/iocore/hostdb/I_HostDBProcessor.h
@@ -175,13 +175,28 @@ struct HostDBInfo : public RefCountObj {
     if (size < sizeof(HostDBInfo)) {
       return nullptr;
     }
-    HostDBInfo *ret = HostDBInfo::alloc(size - sizeof(HostDBInfo));
-    int buf_index   = ret->_iobuffer_index;
+    HostDBInfo *ret      = HostDBInfo::alloc(size - sizeof(HostDBInfo));
+    const auto buf_index = ret->_iobuffer_index;
     memcpy((void *)ret, buf, size);
-    // Reset the refcount back to 0, this is a bit ugly-- but I'm not sure we 
want to expose a method
-    // to mess with the refcount, since this is a fairly unique use case
-    ret                  = new (ret) HostDBInfo();
-    ret->_iobuffer_index = buf_index;
+
+    // Member variables with default member initializers will be overwritten 
by subsequent constructor calls,
+    // so their values are temporarily saved and restored after the 
constructor is executed.
+    const auto key                 = ret->key;
+    const auto hostname_offset     = ret->hostname_offset;
+    const auto ip_timestamp        = ret->ip_timestamp;
+    const auto ip_timeout_interval = ret->ip_timeout_interval;
+
+    // The constructor is invoked for the following reasons:
+    // - To reinitialize the virtual function table pointer (vptr),
+    //   which may have been corrupted by a previous memcpy
+    // - To reset the reference count to zero
+    ret                      = new (ret) HostDBInfo();
+    ret->key                 = key;
+    ret->hostname_offset     = hostname_offset;
+    ret->ip_timestamp        = ip_timestamp;
+    ret->ip_timeout_interval = ip_timeout_interval;
+    ret->_iobuffer_index     = buf_index;
+
     return ret;
   }
 
@@ -319,6 +334,8 @@ struct HostDBInfo : public RefCountObj {
     }
   }
 
+  // NOTE: Using default member initializers can affect the behavior of the 
unmarshall method.
+  //       Ensure that all member variables are properly set within the 
unmarshall method.
   uint64_t key{0};
 
   // Application specific data. NOTE: We need an integral number of
diff --git a/iocore/hostdb/RefCountCache.cc b/iocore/hostdb/RefCountCache.cc
index af9cf0fd20..8f58c37675 100644
--- a/iocore/hostdb/RefCountCache.cc
+++ b/iocore/hostdb/RefCountCache.cc
@@ -49,5 +49,5 @@ RefCountCacheHeader::operator==(RefCountCacheHeader const 
&that) const
 bool
 RefCountCacheHeader::compatible(RefCountCacheHeader *that) const
 {
-  return this->magic == that->magic && this->version == that->version && 
this->object_version == that->version;
+  return this->magic == that->magic && this->version == that->version && 
this->object_version == that->object_version;
 };

Reply via email to