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

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

commit 1a07ca9cdf71715f0de299d91162138cc65b1e7d
Author: Masakazu Kitajo <[email protected]>
AuthorDate: Mon Jun 8 11:29:03 2026 -0600

    Emit type-default for custom log fields with no transaction (#13243)
    
    When a log entry has no backing HttpSM (e.g. a malformed H2/H3
    request rejected before transaction creation), passing
    nullptr to a TSLogFieldRegister'd callback dereferences null
    inside the plugin.  Skip the callback in that case and emit the
    type-appropriate default the way built-in fields do: 0 for ints,
    "-" for strings, AF_UNSPEC for IPs.
    
    (cherry picked from commit e23068d554d331da8ae6f0e78594dc5e19454511)
---
 include/proxy/logging/LogAccess.h |  2 +-
 src/proxy/logging/LogAccess.cc    | 26 ++++++++++++++++++++++++--
 src/proxy/logging/LogField.cc     |  4 ++--
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/include/proxy/logging/LogAccess.h 
b/include/proxy/logging/LogAccess.h
index 31e94d7e4d..35f14ea55c 100644
--- a/include/proxy/logging/LogAccess.h
+++ b/include/proxy/logging/LogAccess.h
@@ -325,7 +325,7 @@ public:
   void set_http_header_field(LogField::Container container, char *field, char 
*buf, int len);
 
   // Plugin
-  int marshal_custom_field(char *buf, const LogField::CustomMarshalFunc 
&plugin_marshal_func);
+  int marshal_custom_field(char *buf, LogField::Type type, const 
LogField::CustomMarshalFunc &plugin_marshal_func);
 
   //
   // unmarshalling routines
diff --git a/src/proxy/logging/LogAccess.cc b/src/proxy/logging/LogAccess.cc
index 690e9a8f5d..0e94137301 100644
--- a/src/proxy/logging/LogAccess.cc
+++ b/src/proxy/logging/LogAccess.cc
@@ -465,9 +465,31 @@ LogAccess::marshal_ip(char *dest, sockaddr const *ip)
 }
 
 int
-LogAccess::marshal_custom_field(char *buf, const LogField::CustomMarshalFunc 
&plugin_marshal_func)
+LogAccess::marshal_custom_field(char *buf, LogField::Type type, const 
LogField::CustomMarshalFunc &plugin_marshal_func)
 {
-  int len = plugin_marshal_func(m_data, buf);
+  void *sm = m_data->http_sm_for_plugins();
+  if (sm == nullptr) {
+    switch (type) {
+    case LogField::sINT:
+    case LogField::dINT:
+      if (buf) {
+        marshal_int(buf, 0);
+      }
+      return INK_MIN_ALIGN;
+    case LogField::STRING: {
+      int len = LogAccess::padded_strlen(nullptr);
+      if (buf) {
+        marshal_str(buf, nullptr, len);
+      }
+      return len;
+    }
+    case LogField::IP:
+      return marshal_ip(buf, nullptr);
+    case LogField::N_TYPES:
+      break;
+    }
+  }
+  int len = plugin_marshal_func(sm, buf);
   return LogAccess::padded_length(len);
 }
 
diff --git a/src/proxy/logging/LogField.cc b/src/proxy/logging/LogField.cc
index 3860f98504..25d6a7f6e9 100644
--- a/src/proxy/logging/LogField.cc
+++ b/src/proxy/logging/LogField.cc
@@ -524,7 +524,7 @@ LogField::marshal_len(LogAccess *lad)
     if (!m_custom_marshal_func) {
       return (lad->*m_marshal_func)(nullptr);
     } else {
-      return lad->marshal_custom_field(nullptr, m_custom_marshal_func);
+      return lad->marshal_custom_field(nullptr, m_type, m_custom_marshal_func);
     }
   }
 
@@ -633,7 +633,7 @@ LogField::marshal(LogAccess *lad, char *buf)
     if (!m_custom_marshal_func) {
       return (lad->*m_marshal_func)(buf);
     } else {
-      return lad->marshal_custom_field(buf, m_custom_marshal_func);
+      return lad->marshal_custom_field(buf, m_type, m_custom_marshal_func);
     }
   }
 

Reply via email to