You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by cm...@apache.org on 2024/06/12 19:41:36 UTC

(trafficserver) branch 10.0.x updated (e80ef92ad1 -> 1a6bbee785)

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

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


    from e80ef92ad1 Add SO_INCOMING_CPU support to net.sock_option_flag_in (#11366)
     new 6fb27c0b73 Pass unused length parameter in HeaderField::append function (#11401)
     new 4aa496ad9b txn_box: Address use after free in Do_upstream_rsp_body (#11428)
     new d8a856cf47 support full range of unsigned char for hex conversion.   (#11429)
     new c55a9cdbf3 Fix building without HWLOC (#11435)
     new d4eebce880 access_control: Remove unused dumpHeaders (#11439)
     new 1a6bbee785 Fix race condition causing interleaved logs  (#11432)

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../api/functions/TSMimeHdrPrint.en.rst            |  4 +-
 example/plugins/c-api/cache_scan/cache_scan.cc     |  2 +-
 .../plugins/c-api/output_header/output_header.cc   |  2 +-
 include/proxy/hdrs/HTTP.h                          | 10 ++--
 include/proxy/hdrs/MIME.h                          |  7 +--
 include/proxy/http/HttpTransact.h                  | 66 +++++++++++++++-------
 include/ts/ts.h                                    |  8 +--
 include/tsutil/StringConvert.h                     | 12 ++--
 plugins/background_fetch/background_fetch.cc       |  2 +-
 plugins/background_fetch/headers.cc                |  4 +-
 plugins/background_fetch/headers.h                 |  2 +-
 plugins/experimental/access_control/headers.cc     | 39 -------------
 plugins/experimental/access_control/headers.h      |  1 -
 .../experimental/cache_fill/background_fetch.cc    |  6 +-
 plugins/experimental/stale_response/CacheUpdate.cc |  6 +-
 .../experimental/txn_box/plugin/src/Machinery.cc   |  9 +++
 plugins/prefetch/fetch.cc                          |  2 +-
 plugins/prefetch/headers.cc                        |  5 +-
 plugins/prefetch/headers.h                         |  2 +-
 src/api/InkAPI.cc                                  | 18 +++---
 src/iocore/net/Connection.cc                       |  2 +-
 src/proxy/hdrs/HTTP.cc                             | 10 ++--
 src/proxy/hdrs/MIME.cc                             | 11 ++--
 src/proxy/hdrs/unit_tests/test_HdrUtils.cc         |  4 +-
 src/proxy/http/HttpSM.cc                           |  4 +-
 src/proxy/http/HttpTransact.cc                     | 30 +++++-----
 src/tscpp/api/Headers.cc                           |  2 +-
 src/tsutil/CMakeLists.txt                          |  1 +
 src/tsutil/unit_tests/test_StringConvert.cc        | 12 ++++
 29 files changed, 144 insertions(+), 139 deletions(-)


(trafficserver) 05/06: access_control: Remove unused dumpHeaders (#11439)

Posted by cm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d4eebce8801e0f180d3831b7c723fe29f6d33f2e
Author: Brian Neradt <br...@gmail.com>
AuthorDate: Mon Jun 10 15:49:39 2024 -0500

    access_control: Remove unused dumpHeaders (#11439)
    
    dumpHeaders is unused, so removing it.
    
    (cherry picked from commit 69a430e8b5fea90d51f2d81bac11e7082fff154d)
---
 plugins/experimental/access_control/headers.cc | 39 --------------------------
 plugins/experimental/access_control/headers.h  |  1 -
 2 files changed, 40 deletions(-)

diff --git a/plugins/experimental/access_control/headers.cc b/plugins/experimental/access_control/headers.cc
index e0d1e87a19..ebfdf5f34a 100644
--- a/plugins/experimental/access_control/headers.cc
+++ b/plugins/experimental/access_control/headers.cc
@@ -172,42 +172,3 @@ setHeader(TSMBuffer bufp, TSMLoc hdrLoc, const char *header, int headerlen, cons
 
   return ret;
 }
-
-/**
- * @brief Dump a header on stderr
- *
- * Useful together with Dbg().
- *
- * @param bufp request's buffer
- * @param hdrLoc request's header location
- */
-void
-dumpHeaders(TSMBuffer bufp, TSMLoc hdrLoc)
-{
-  TSIOBuffer       output_buffer;
-  TSIOBufferReader reader;
-  TSIOBufferBlock  block;
-  const char      *block_start;
-  int64_t          block_avail;
-
-  output_buffer = TSIOBufferCreate();
-  reader        = TSIOBufferReaderAlloc(output_buffer);
-
-  /* This will print  just MIMEFields and not the http request line */
-  TSMimeHdrPrint(bufp, hdrLoc, output_buffer);
-
-  /* We need to loop over all the buffer blocks, there can be more than 1 */
-  block = TSIOBufferReaderStart(reader);
-  do {
-    block_start = TSIOBufferBlockReadStart(block, reader, &block_avail);
-    if (block_avail > 0) {
-      AccessControlDebug("Headers are:\n%.*s", static_cast<int>(block_avail), block_start);
-    }
-    TSIOBufferReaderConsume(reader, block_avail);
-    block = TSIOBufferReaderStart(reader);
-  } while (block && block_avail != 0);
-
-  /* Free up the TSIOBuffer that we used to print out the header */
-  TSIOBufferReaderFree(reader);
-  TSIOBufferDestroy(output_buffer);
-}
diff --git a/plugins/experimental/access_control/headers.h b/plugins/experimental/access_control/headers.h
index 51d7423eac..dd6567bd43 100644
--- a/plugins/experimental/access_control/headers.h
+++ b/plugins/experimental/access_control/headers.h
@@ -29,4 +29,3 @@ int   removeHeader(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len);
 bool  headerExist(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len);
 char *getHeader(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int headerlen, char *value, int *valuelen);
 bool setHeader(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len, const char *val, int val_len, bool duplicateOk = false);
-void dumpHeaders(TSMBuffer bufp, TSMLoc hdr_loc);


(trafficserver) 06/06: Fix race condition causing interleaved logs (#11432)

Posted by cm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1a6bbee785b3b9d7178cbcc717867de66cc84d33
Author: JosiahWI <41...@users.noreply.github.com>
AuthorDate: Tue Jun 11 15:16:08 2024 -0500

    Fix race condition causing interleaved logs  (#11432)
    
    * Remove unused argument from mime_hdr_print
    
    This removes the unused heap argument and updates calls across the whole
    codebase accordingly.
    
    * Constify some arguments for MIME printing
    
    This constifies some arguments to mime_field_print and mime_hdr_print and
    updates usage throughout the codebase accordingly.
    
    * Remove unused argument from http_hdr_print
    
    This removes the heap argument from the method and updates the usage
    throughout the codebase.
    
    * Constify argument to http_hdr_status_get
    
    * Constify argument to http_hdr_print
    
    This marks the hdr argument to http_hdr_print as const.
    
    * Constify the HTTPHdr::print method
    
    * Fix race condition causing interleaved logs
    
    The output of the `DUMP_HEADER` macro was being written in multiple calls to
    fprintf() that raced with other logging, resulting in interleaved output that
    intermittently failed the ja3_fingerprint AuTest on CI. Whether other AuTest
    failures were related to the same issue is unknown at this point.
    
    This fixes the race condition by batching the calls to a single fprintf() call.
    This also refactors the macro to two inline functions. In a benchmark using an
    expanded version of the headers in the HttpTransact tests, a 60% speedup was
    measured over the macro if all the header data fit in the buffer. In the worst
    case that the buffer could only hold a byte at a time, the speedup was 80%.
    The benchmark was compiled with -O3 and stderr was piped to /dev/null.
    
    These were the headers used for the benchmark:
    ```
      header input1[] = {
        {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "111111111111111111111111"},
        {"BBB",                               "222"                     },
        {"CCC",                               "333"                     },
        {"DDD",                               "333"                     },
        {"EEE",                               "333"                     },
        {"FFF",                               "333"                     },
        {"GGG",                               "333"                     },
        {"HHH",                               "333"                     },
        {"III",                               "333"                     },
        {"JJJ",                               "333"                     },
        {"KKK",                               "333"                     },
      };
    ```
    
    This fixes #11431.
    
    * Implement changes requested by Brian Neradt
    
    This makes the following changes:
    
     * The length parameter to string::append is used instead of adding a
       null terminator.
     * Some erroneous logic left over from testing is fixed.
    
    * Fix formatting
    
    * Add log output to dump_header for invalid hdrs
    
    * Remove bufp parameter from TSMimeHdrPrint
    
    This is an API change. The parameter is no longer used, so this commit removes
    it and updates the developer documentation and core plugins accordingly.
    
    * Fix the example plugins
    
    Since the API changed, the example plugins now need updating as well.
    
    (cherry picked from commit 054b6a80439532b6c74be6b8c27f494a9f8330e2)
---
 .../api/functions/TSMimeHdrPrint.en.rst            |  4 +-
 example/plugins/c-api/cache_scan/cache_scan.cc     |  2 +-
 .../plugins/c-api/output_header/output_header.cc   |  2 +-
 include/proxy/hdrs/HTTP.h                          | 10 ++--
 include/proxy/hdrs/MIME.h                          |  7 +--
 include/proxy/http/HttpTransact.h                  | 66 +++++++++++++++-------
 include/ts/ts.h                                    |  8 +--
 plugins/background_fetch/background_fetch.cc       |  2 +-
 plugins/background_fetch/headers.cc                |  4 +-
 plugins/background_fetch/headers.h                 |  2 +-
 .../experimental/cache_fill/background_fetch.cc    |  6 +-
 plugins/experimental/stale_response/CacheUpdate.cc |  6 +-
 plugins/prefetch/fetch.cc                          |  2 +-
 plugins/prefetch/headers.cc                        |  5 +-
 plugins/prefetch/headers.h                         |  2 +-
 src/api/InkAPI.cc                                  | 18 +++---
 src/proxy/hdrs/HTTP.cc                             | 10 ++--
 src/proxy/hdrs/MIME.cc                             | 11 ++--
 src/proxy/hdrs/unit_tests/test_HdrUtils.cc         |  4 +-
 src/proxy/http/HttpSM.cc                           |  4 +-
 src/proxy/http/HttpTransact.cc                     | 30 +++++-----
 21 files changed, 112 insertions(+), 93 deletions(-)

diff --git a/doc/developer-guide/api/functions/TSMimeHdrPrint.en.rst b/doc/developer-guide/api/functions/TSMimeHdrPrint.en.rst
index 294dc51d50..5049f8b544 100644
--- a/doc/developer-guide/api/functions/TSMimeHdrPrint.en.rst
+++ b/doc/developer-guide/api/functions/TSMimeHdrPrint.en.rst
@@ -28,10 +28,10 @@ Synopsis
 
     #include <ts/ts.h>
 
-.. function:: void TSMimeHdrPrint(TSMBuffer bufp, TSMLoc offset, TSIOBuffer iobufp)
+.. function:: void TSMimeHdrPrint(TSMLoc offset, TSIOBuffer iobufp)
 
 Description
 ===========
 
-Formats the MIME header located at :arg:`hdr_loc` within :arg:`bufp` into the
+Formats the MIME header located at :arg:`hdr_loc` into the
 :cpp:type:`TSIOBuffer` :arg:`iobufp`.
diff --git a/example/plugins/c-api/cache_scan/cache_scan.cc b/example/plugins/c-api/cache_scan/cache_scan.cc
index 26a67dc17e..8b4022be51 100644
--- a/example/plugins/c-api/cache_scan/cache_scan.cc
+++ b/example/plugins/c-api/cache_scan/cache_scan.cc
@@ -144,7 +144,7 @@ handle_scan(TSCont contp, TSEvent event, void *edata)
     // print the response headers
     TSCacheHttpInfoRespGet(cache_infop, &resp_bufp, &resp_hdr_loc);
     cstate->total_bytes += TSMimeHdrLengthGet(resp_bufp, resp_hdr_loc);
-    TSMimeHdrPrint(resp_bufp, resp_hdr_loc, cstate->resp_buffer);
+    TSMimeHdrPrint(resp_hdr_loc, cstate->resp_buffer);
     TSHandleMLocRelease(resp_bufp, TS_NULL_MLOC, resp_hdr_loc);
 
     cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s2, sizeof(s2) - 1);
diff --git a/example/plugins/c-api/output_header/output_header.cc b/example/plugins/c-api/output_header/output_header.cc
index 6f046dbc89..46fdf9fadc 100644
--- a/example/plugins/c-api/output_header/output_header.cc
+++ b/example/plugins/c-api/output_header/output_header.cc
@@ -74,7 +74,7 @@ handle_dns(TSHttpTxn txnp, TSCont contp ATS_UNUSED)
   /* This will print  just MIMEFields and not
      the http request line */
   Dbg(dbg_ctl, "Printing the hdrs ... ");
-  TSMimeHdrPrint(bufp, hdr_loc, output_buffer);
+  TSMimeHdrPrint(hdr_loc, output_buffer);
 
   if (TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc) == TS_ERROR) {
     Dbg(dbg_ctl, "non-fatal: error releasing MLoc");
diff --git a/include/proxy/hdrs/HTTP.h b/include/proxy/hdrs/HTTP.h
index ca7a2b4155..f0eb0dad67 100644
--- a/include/proxy/hdrs/HTTP.h
+++ b/include/proxy/hdrs/HTTP.h
@@ -428,7 +428,7 @@ void         http_hdr_init(HdrHeap *heap, HTTPHdrImpl *hh, HTTPType polarity, HT
 HTTPHdrImpl *http_hdr_clone(HTTPHdrImpl *s_hh, HdrHeap *s_heap, HdrHeap *d_heap);
 void         http_hdr_copy_onto(HTTPHdrImpl *s_hh, HdrHeap *s_heap, HTTPHdrImpl *d_hh, HdrHeap *d_heap, bool inherit_strs);
 
-int http_hdr_print(HdrHeap *heap, HTTPHdrImpl *hh, char *buf, int bufsize, int *bufindex, int *dumpoffset);
+int http_hdr_print(HTTPHdrImpl const *hh, char *buf, int bufsize, int *bufindex, int *dumpoffset);
 
 void http_hdr_describe(HdrHeapObjImpl *obj, bool recurse = true);
 
@@ -506,7 +506,7 @@ public:
 
   int unmarshal(char *buf, int len, RefCountObj *block_ref);
 
-  int print(char *buf, int bufsize, int *bufindex, int *dumpoffset);
+  int print(char *buf, int bufsize, int *bufindex, int *dumpoffset) const;
 
   int length_get() const;
 
@@ -761,10 +761,10 @@ HTTPHdr::copy_shallow(const HTTPHdr *hdr)
   -------------------------------------------------------------------------*/
 
 inline int
-HTTPHdr::print(char *buf, int bufsize, int *bufindex, int *dumpoffset)
+HTTPHdr::print(char *buf, int bufsize, int *bufindex, int *dumpoffset) const
 {
   ink_assert(valid());
-  return http_hdr_print(m_heap, m_http, buf, bufsize, bufindex, dumpoffset);
+  return http_hdr_print(m_http, buf, bufsize, bufindex, dumpoffset);
 }
 
 /*-------------------------------------------------------------------------
@@ -1068,7 +1068,7 @@ HTTPHdr::url_set(const char *str, int length)
   -------------------------------------------------------------------------*/
 
 inline HTTPStatus
-http_hdr_status_get(HTTPHdrImpl *hh)
+http_hdr_status_get(HTTPHdrImpl const *hh)
 {
   ink_assert(hh->m_polarity == HTTP_TYPE_RESPONSE);
   return (HTTPStatus)hh->u.resp.m_status;
diff --git a/include/proxy/hdrs/MIME.h b/include/proxy/hdrs/MIME.h
index 6a5661698d..e4114767b0 100644
--- a/include/proxy/hdrs/MIME.h
+++ b/include/proxy/hdrs/MIME.h
@@ -903,13 +903,12 @@ ParseResult mime_parser_parse(MIMEParser *parser, HdrHeap *heap, MIMEHdrImpl *mh
 void mime_hdr_describe(HdrHeapObjImpl *raw, bool recurse);
 void mime_field_block_describe(HdrHeapObjImpl *raw, bool recurse);
 
-int mime_hdr_print(HdrHeap *heap, MIMEHdrImpl *mh, char *buf_start, int buf_length, int *buf_index_inout,
-                   int *buf_chars_to_skip_inout);
+int mime_hdr_print(MIMEHdrImpl const *mh, char *buf_start, int buf_length, int *buf_index_inout, int *buf_chars_to_skip_inout);
 int mime_mem_print(const char *src_d, int src_l, char *buf_start, int buf_length, int *buf_index_inout,
                    int *buf_chars_to_skip_inout);
 int mime_mem_print_lc(const char *src_d, int src_l, char *buf_start, int buf_length, int *buf_index_inout,
                       int *buf_chars_to_skip_inout);
-int mime_field_print(MIMEField *field, char *buf_start, int buf_length, int *buf_index_inout, int *buf_chars_to_skip_inout);
+int mime_field_print(MIMEField const *field, char *buf_start, int buf_length, int *buf_index_inout, int *buf_chars_to_skip_inout);
 
 const char *mime_str_u16_set(HdrHeap *heap, const char *s_str, int s_len, const char **d_str, uint16_t *d_len, bool must_copy);
 
@@ -1409,7 +1408,7 @@ MIMEHdr::presence(uint64_t mask) const
 inline int
 MIMEHdr::print(char *buf, int bufsize, int *bufindex, int *chars_to_skip)
 {
-  return mime_hdr_print(m_heap, m_mime, buf, bufsize, bufindex, chars_to_skip);
+  return mime_hdr_print(m_mime, buf, bufsize, bufindex, chars_to_skip);
 }
 
 /*-------------------------------------------------------------------------
diff --git a/include/proxy/http/HttpTransact.h b/include/proxy/http/HttpTransact.h
index 480c8e7eb4..84761f1c53 100644
--- a/include/proxy/http/HttpTransact.h
+++ b/include/proxy/http/HttpTransact.h
@@ -25,6 +25,7 @@
 
 #include <cstddef>
 
+#include "tsutil/DbgCtl.h"
 #include "tscore/ink_assert.h"
 #include "tscore/ink_platform.h"
 #include "iocore/hostdb/HostDB.h"
@@ -45,31 +46,56 @@
 #include "proxy/ProxySession.h"
 #include "tscore/MgmtDefs.h"
 
+#include <cstdint>
+#include <cstdio>
+#include <string>
+#include <string_view>
+
 #define HTTP_OUR_VIA_MAX_LENGTH 1024 // 512-bytes for hostname+via string, 512-bytes for the debug info
 
 #define HTTP_RELEASE_ASSERT(X) ink_release_assert(X)
 
-#define DUMP_HEADER(C, H, I, S)                                 \
-  {                                                             \
-    if ((C).on()) {                                             \
-      fprintf(stderr, "+++++++++ %s +++++++++\n", S);           \
-      fprintf(stderr, "-- State Machine Id: %" PRId64 "\n", I); \
-      char b[4096];                                             \
-      int  used, tmp, offset;                                   \
-      int  done;                                                \
-      offset = 0;                                               \
-      if ((H)->valid()) {                                       \
-        do {                                                    \
-          used     = 0;                                         \
-          tmp      = offset;                                    \
-          done     = (H)->print(b, 4095, &used, &tmp);          \
-          offset  += used;                                      \
-          b[used]  = '\0';                                      \
-          fprintf(stderr, "%s", b);                             \
-        } while (!done);                                        \
-      }                                                         \
-    }                                                           \
+inline void
+s_dump_header(HTTPHdr const *hdr, std::string &out)
+{
+  int offset{0};
+  int done{0};
+  do {
+    int  used{0};
+    char b[4096];
+    // The buffer offset is taken non-const and it is apparently
+    // modified in some code path, but in my testing it does
+    // not change, it seems. Since we manually bump the offset,
+    // the use of tmp is precautionary to make sure our logic
+    // doesn't break in case it does change in some circumstance.
+    int tmp{offset};
+    done    = hdr->print(b, 4096, &used, &tmp);
+    offset += used;
+    out.append(b, used);
+  } while (0 == done);
+}
+
+inline void
+dump_header(DbgCtl const &ctl, HTTPHdr const *hdr, std::int64_t sm_id, std::string_view description)
+{
+  if (ctl.on()) {
+    std::string output;
+    output.append("+++++++++ ");
+    output.append(description);
+    output.append(" +++++++++\n");
+    output.append("-- State Machine Id: ");
+    output.append(std::to_string(sm_id));
+    output.push_back('\n');
+    if (hdr->valid()) {
+      s_dump_header(hdr, output);
+    } else {
+      output.append("Invalid header!\n");
+    }
+    // We make a single call to fprintf so that the output does not get
+    // interleaved with output from other threads performing I/O.
+    fprintf(stderr, "%s", output.c_str());
   }
+}
 
 using ink_time_t = time_t;
 
diff --git a/include/ts/ts.h b/include/ts/ts.h
index c8d93f91ba..075fea93ee 100644
--- a/include/ts/ts.h
+++ b/include/ts/ts.h
@@ -878,16 +878,14 @@ TSReturnCode TSMimeHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_
 TSReturnCode TSMimeHdrCopy(TSMBuffer dest_bufp, TSMLoc dest_offset, TSMBuffer src_bufp, TSMLoc src_offset);
 
 /**
-    Formats the MIME header located at hdr_loc within bufp into the
+    Formats the MIME header located at hdr_loc into the
     TSIOBuffer iobufp.
 
-    @param bufp marshal buffer containing the header to be copied to
-      an TSIOBuffer.
-    @param offset
+    @param offset The offset of the header to be copied to a TSIOBuffer.
     @param iobufp target TSIOBuffer.
 
  */
-void TSMimeHdrPrint(TSMBuffer bufp, TSMLoc offset, TSIOBuffer iobufp);
+void TSMimeHdrPrint(TSMLoc offset, TSIOBuffer iobufp);
 
 /**
     Parses a MIME header. The MIME header must have already been
diff --git a/plugins/background_fetch/background_fetch.cc b/plugins/background_fetch/background_fetch.cc
index 78a5ee9d4f..38c10b6775 100644
--- a/plugins/background_fetch/background_fetch.cc
+++ b/plugins/background_fetch/background_fetch.cc
@@ -388,7 +388,7 @@ cont_bg_fetch(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
         break;
       }
       Dbg(Bg_dbg_ctl, "Starting background fetch, replaying:");
-      dump_headers(data->mbuf, data->hdr_loc);
+      dump_headers(data->hdr_loc);
     }
 
     // Setup the NetVC for background fetch
diff --git a/plugins/background_fetch/headers.cc b/plugins/background_fetch/headers.cc
index d29025eca9..a0bf864256 100644
--- a/plugins/background_fetch/headers.cc
+++ b/plugins/background_fetch/headers.cc
@@ -95,14 +95,14 @@ set_header(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len, const ch
 ///////////////////////////////////////////////////////////////////////////
 // Dump a header on stderr, useful together with Dbg().
 void
-dump_headers(TSMBuffer bufp, TSMLoc hdr_loc)
+dump_headers(TSMLoc hdr_loc)
 {
   TSIOBuffer       output_buffer = TSIOBufferCreate();
   TSIOBufferReader reader        = TSIOBufferReaderAlloc(output_buffer);
   int64_t          block_avail   = 0;
 
   /* This will print  just MIMEFields and not the http request line */
-  TSMimeHdrPrint(bufp, hdr_loc, output_buffer);
+  TSMimeHdrPrint(hdr_loc, output_buffer);
 
   /* We need to loop over all the buffer blocks, there can be more than 1 */
   TSIOBufferBlock block = TSIOBufferReaderStart(reader);
diff --git a/plugins/background_fetch/headers.h b/plugins/background_fetch/headers.h
index c633930126..426a3c6d2e 100644
--- a/plugins/background_fetch/headers.h
+++ b/plugins/background_fetch/headers.h
@@ -26,4 +26,4 @@
 
 int  remove_header(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len);
 bool set_header(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len, const char *val, int val_len);
-void dump_headers(TSMBuffer bufp, TSMLoc hdr_loc);
+void dump_headers(TSMLoc hdr_loc);
diff --git a/plugins/experimental/cache_fill/background_fetch.cc b/plugins/experimental/cache_fill/background_fetch.cc
index b69f30ed81..1881edddd1 100644
--- a/plugins/experimental/cache_fill/background_fetch.cc
+++ b/plugins/experimental/cache_fill/background_fetch.cc
@@ -93,7 +93,7 @@ set_header(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len, const ch
 ///////////////////////////////////////////////////////////////////////////
 // Dump a header on stderr, useful together with Dbg().
 static void
-dump_headers(TSMBuffer bufp, TSMLoc hdr_loc)
+dump_headers(TSMLoc hdr_loc)
 {
   TSIOBuffer       output_buffer;
   TSIOBufferReader reader;
@@ -104,7 +104,7 @@ dump_headers(TSMBuffer bufp, TSMLoc hdr_loc)
   reader        = TSIOBufferReaderAlloc(output_buffer);
 
   /* This will print  just MIMEFields and not the http request line */
-  TSMimeHdrPrint(bufp, hdr_loc, output_buffer);
+  TSMimeHdrPrint(hdr_loc, output_buffer);
 
   /* We need to loop over all the buffer blocks, there can be more than 1 */
   block = TSIOBufferReaderStart(reader);
@@ -241,7 +241,7 @@ cont_bg_fetch(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
         break;
       }
       Dbg(dbg_ctl, "Starting background fetch, replaying:");
-      dump_headers(data->mbuf, data->hdr_loc);
+      dump_headers(data->hdr_loc);
     }
 
     // Setup the NetVC for background fetch
diff --git a/plugins/experimental/stale_response/CacheUpdate.cc b/plugins/experimental/stale_response/CacheUpdate.cc
index 979fcc4a55..10f07c576f 100644
--- a/plugins/experimental/stale_response/CacheUpdate.cc
+++ b/plugins/experimental/stale_response/CacheUpdate.cc
@@ -44,7 +44,7 @@ const int  SERVER_INTERCEPT_HEADER_LEN = sizeof(SERVER_INTERCEPT_HEADER) - 1;
 
 /*-----------------------------------------------------------------------------------------------*/
 static char *
-convert_mime_hdr_to_string(TSMBuffer bufp, TSMLoc hdr_loc)
+convert_mime_hdr_to_string(TSMLoc hdr_loc)
 {
   TSIOBuffer       output_buffer;
   TSIOBufferReader reader;
@@ -67,7 +67,7 @@ convert_mime_hdr_to_string(TSMBuffer bufp, TSMLoc hdr_loc)
 
   /* This will print  just MIMEFields and not
      the http request line */
-  TSMimeHdrPrint(bufp, hdr_loc, output_buffer);
+  TSMimeHdrPrint(hdr_loc, output_buffer);
 
   /* Find out how the big the complete header is by
      seeing the total bytes in the buffer.  We need to
@@ -341,7 +341,7 @@ intercept_fetch_the_url(StateInfo *state)
   get_request.append(tmpStr, 8);
   get_request.append("\r\n");
 
-  char *allReqHeaders = convert_mime_hdr_to_string(state->req_info->http_hdr_buf, state->req_info->http_hdr_loc);
+  char *allReqHeaders = convert_mime_hdr_to_string(state->req_info->http_hdr_loc);
   get_request.append(allReqHeaders);
   TSfree(allReqHeaders);
   get_request.append("\r\n");
diff --git a/plugins/prefetch/fetch.cc b/plugins/prefetch/fetch.cc
index cf571250a2..9c31e7bcf3 100644
--- a/plugins/prefetch/fetch.cc
+++ b/plugins/prefetch/fetch.cc
@@ -690,7 +690,7 @@ BgFetch::handler(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
         break;
       }
       PrefetchDebug("Starting background fetch.");
-      dumpHeaders(fetch->_mbuf, fetch->_headerLoc);
+      dumpHeaders(fetch->_headerLoc);
     }
 
     // Setup the NetVC for background fetch
diff --git a/plugins/prefetch/headers.cc b/plugins/prefetch/headers.cc
index 027d4b3013..58e64acb94 100644
--- a/plugins/prefetch/headers.cc
+++ b/plugins/prefetch/headers.cc
@@ -178,11 +178,10 @@ setHeader(TSMBuffer bufp, TSMLoc hdrLoc, const char *header, int headerlen, cons
  *
  * Useful together with Dbg().
  *
- * @param bufp request's buffer
  * @param hdrLoc request's header location
  */
 void
-dumpHeaders(TSMBuffer bufp, TSMLoc hdrLoc)
+dumpHeaders(TSMLoc hdrLoc)
 {
   TSIOBuffer       output_buffer;
   TSIOBufferReader reader;
@@ -194,7 +193,7 @@ dumpHeaders(TSMBuffer bufp, TSMLoc hdrLoc)
   reader        = TSIOBufferReaderAlloc(output_buffer);
 
   /* This will print  just MIMEFields and not the http request line */
-  TSMimeHdrPrint(bufp, hdrLoc, output_buffer);
+  TSMimeHdrPrint(hdrLoc, output_buffer);
 
   /* We need to loop over all the buffer blocks, there can be more than 1 */
   block = TSIOBufferReaderStart(reader);
diff --git a/plugins/prefetch/headers.h b/plugins/prefetch/headers.h
index 2f72063447..2bacd58c2b 100644
--- a/plugins/prefetch/headers.h
+++ b/plugins/prefetch/headers.h
@@ -28,4 +28,4 @@ bool  headerExist(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len);
 char *getHeader(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int headerlen, char *value, int *valuelen);
 
 bool setHeader(TSMBuffer bufp, TSMLoc hdr_loc, const char *header, int len, const char *val, int val_len);
-void dumpHeaders(TSMBuffer bufp, TSMLoc hdr_loc);
+void dumpHeaders(TSMLoc hdr_loc);
diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc
index 0d35d8ebd9..00dc781dee 100644
--- a/src/api/InkAPI.cc
+++ b/src/api/InkAPI.cc
@@ -1514,19 +1514,17 @@ TSMimeHdrCopy(TSMBuffer dest_bufp, TSMLoc dest_obj, TSMBuffer src_bufp, TSMLoc s
 }
 
 void
-TSMimeHdrPrint(TSMBuffer bufp, TSMLoc obj, TSIOBuffer iobufp)
+TSMimeHdrPrint(TSMLoc obj, TSIOBuffer iobufp)
 {
-  sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS);
   sdk_assert((sdk_sanity_check_mime_hdr_handle(obj) == TS_SUCCESS) || (sdk_sanity_check_http_hdr_handle(obj) == TS_SUCCESS));
   sdk_assert(sdk_sanity_check_iocore_structure(iobufp) == TS_SUCCESS);
 
-  HdrHeap       *heap = ((HdrHeapSDKHandle *)bufp)->m_heap;
-  MIMEHdrImpl   *mh   = _hdr_mloc_to_mime_hdr_impl(obj);
-  MIOBuffer     *b    = (MIOBuffer *)iobufp;
-  IOBufferBlock *blk;
-  int            bufindex;
-  int            tmp, dumpoffset = 0;
-  int            done;
+  MIMEHdrImpl const *mh = _hdr_mloc_to_mime_hdr_impl(obj);
+  MIOBuffer         *b  = (MIOBuffer *)iobufp;
+  IOBufferBlock     *blk;
+  int                bufindex;
+  int                tmp, dumpoffset = 0;
+  int                done;
 
   do {
     blk = b->get_current_block();
@@ -1537,7 +1535,7 @@ TSMimeHdrPrint(TSMBuffer bufp, TSMLoc obj, TSIOBuffer iobufp)
 
     bufindex = 0;
     tmp      = dumpoffset;
-    done     = mime_hdr_print(heap, mh, blk->end(), blk->write_avail(), &bufindex, &tmp);
+    done     = mime_hdr_print(mh, blk->end(), blk->write_avail(), &bufindex, &tmp);
 
     dumpoffset += bufindex;
     b->fill(bufindex);
diff --git a/src/proxy/hdrs/HTTP.cc b/src/proxy/hdrs/HTTP.cc
index 166d896599..5f33a44788 100644
--- a/src/proxy/hdrs/HTTP.cc
+++ b/src/proxy/hdrs/HTTP.cc
@@ -429,7 +429,7 @@ http_version_print(const HTTPVersion &version, char *buf, int bufsize, int *bufi
   -------------------------------------------------------------------------*/
 
 int
-http_hdr_print(HdrHeap *heap, HTTPHdrImpl *hdr, char *buf, int bufsize, int *bufindex, int *dumpoffset)
+http_hdr_print(HTTPHdrImpl const *hdr, char *buf, int bufsize, int *bufindex, int *dumpoffset)
 {
 #define TRY(x) \
   if (!x)      \
@@ -484,7 +484,7 @@ http_hdr_print(HdrHeap *heap, HTTPHdrImpl *hdr, char *buf, int bufsize, int *buf
         TRY(mime_mem_print("\r\n", 2, buf, bufsize, bufindex, dumpoffset));
       }
 
-      TRY(mime_hdr_print(heap, hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset));
+      TRY(mime_hdr_print(hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset));
 
     } else {
       TRY(mime_mem_print(hdr->u.req.m_ptr_method, hdr->u.req.m_len_method, buf, bufsize, bufindex, dumpoffset));
@@ -500,7 +500,7 @@ http_hdr_print(HdrHeap *heap, HTTPHdrImpl *hdr, char *buf, int bufsize, int *buf
 
       TRY(mime_mem_print("\r\n", 2, buf, bufsize, bufindex, dumpoffset));
 
-      TRY(mime_hdr_print(heap, hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset));
+      TRY(mime_hdr_print(hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset));
     }
 
   } else { //  hdr->m_polarity == HTTP_TYPE_RESPONSE
@@ -540,7 +540,7 @@ http_hdr_print(HdrHeap *heap, HTTPHdrImpl *hdr, char *buf, int bufsize, int *buf
         TRY(mime_mem_print("\r\n", 2, buf, bufsize, bufindex, dumpoffset));
       }
 
-      TRY(mime_hdr_print(heap, hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset));
+      TRY(mime_hdr_print(hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset));
 
     } else {
       TRY(http_version_print(hdr->m_version, buf, bufsize, bufindex, dumpoffset));
@@ -559,7 +559,7 @@ http_hdr_print(HdrHeap *heap, HTTPHdrImpl *hdr, char *buf, int bufsize, int *buf
 
       TRY(mime_mem_print("\r\n", 2, buf, bufsize, bufindex, dumpoffset));
 
-      TRY(mime_hdr_print(heap, hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset));
+      TRY(mime_hdr_print(hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset));
     }
   }
 
diff --git a/src/proxy/hdrs/MIME.cc b/src/proxy/hdrs/MIME.cc
index 5dbcb349c0..5194148755 100644
--- a/src/proxy/hdrs/MIME.cc
+++ b/src/proxy/hdrs/MIME.cc
@@ -2710,12 +2710,11 @@ mime_field_block_describe(HdrHeapObjImpl *raw, bool /* recurse ATS_UNUSED */)
 }
 
 int
-mime_hdr_print(HdrHeap * /* heap ATS_UNUSED */, MIMEHdrImpl *mh, char *buf_start, int buf_length, int *buf_index_inout,
-               int *buf_chars_to_skip_inout)
+mime_hdr_print(MIMEHdrImpl const *mh, char *buf_start, int buf_length, int *buf_index_inout, int *buf_chars_to_skip_inout)
 {
-  MIMEFieldBlockImpl *fblock;
-  MIMEField          *field;
-  uint32_t            index;
+  MIMEFieldBlockImpl const *fblock;
+  MIMEField const          *field;
+  uint32_t                  index;
 
 #define SIMPLE_MIME_HDR_PRINT
 #ifdef SIMPLE_MIME_HDR_PRINT
@@ -2825,7 +2824,7 @@ mime_mem_print_lc(const char *src_d, int src_l, char *buf_start, int buf_length,
 }
 
 int
-mime_field_print(MIMEField *field, char *buf_start, int buf_length, int *buf_index_inout, int *buf_chars_to_skip_inout)
+mime_field_print(MIMEField const *field, char *buf_start, int buf_length, int *buf_index_inout, int *buf_chars_to_skip_inout)
 {
 #define TRY(x) \
   if (!x)      \
diff --git a/src/proxy/hdrs/unit_tests/test_HdrUtils.cc b/src/proxy/hdrs/unit_tests/test_HdrUtils.cc
index bfaa647ae1..7e34d2a911 100644
--- a/src/proxy/hdrs/unit_tests/test_HdrUtils.cc
+++ b/src/proxy/hdrs/unit_tests/test_HdrUtils.cc
@@ -158,7 +158,7 @@ TEST_CASE("HdrUtils 2", "[proxy][hdrutils]")
 
   int  idx   = 0;
   int  skip  = 0;
-  auto parse = mime_hdr_print(heap, mime.m_mime, buff, static_cast<int>(sizeof(buff)), &idx, &skip);
+  auto parse = mime_hdr_print(mime.m_mime, buff, static_cast<int>(sizeof(buff)), &idx, &skip);
   REQUIRE(parse != 0);
   REQUIRE(idx == static_cast<int>(text.size()));
   REQUIRE(0 == memcmp(swoc::TextView(buff, idx), text));
@@ -201,7 +201,7 @@ TEST_CASE("HdrUtils 3", "[proxy][hdrutils]")
 
   int  idx   = 0;
   int  skip  = 0;
-  auto parse = mime_hdr_print(heap, mime.m_mime, buff, static_cast<int>(sizeof(buff)), &idx, &skip);
+  auto parse = mime_hdr_print(mime.m_mime, buff, static_cast<int>(sizeof(buff)), &idx, &skip);
   REQUIRE(parse != 0);
   REQUIRE(idx == static_cast<int>(text.size()));
   REQUIRE(0 == memcmp(swoc::TextView(buff, idx), text));
diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc
index b6bf68c3a6..847be6e441 100644
--- a/src/proxy/http/HttpSM.cc
+++ b/src/proxy/http/HttpSM.cc
@@ -6588,7 +6588,7 @@ HttpSM::setup_server_send_request()
     t_state.hdr_info.server_request.value_set_int64(MIME_FIELD_CONTENT_LENGTH, MIME_LEN_CONTENT_LENGTH, msg_len);
   }
 
-  DUMP_HEADER(dbg_ctl_http_hdrs, &(t_state.hdr_info.server_request), sm_id, "Proxy's Request after hooks");
+  dump_header(dbg_ctl_http_hdrs, &(t_state.hdr_info.server_request), sm_id, "Proxy's Request after hooks");
 
   // We need a reader so bytes don't fall off the end of
   //  the buffer
@@ -8472,7 +8472,7 @@ HttpSM::redirect_request(const char *arg_redirect_url, const int arg_redirect_le
     }
   }
 
-  DUMP_HEADER(dbg_ctl_http_hdrs, &t_state.hdr_info.client_request, sm_id, "Framed Client Request..checking");
+  dump_header(dbg_ctl_http_hdrs, &t_state.hdr_info.client_request, sm_id, "Framed Client Request..checking");
 }
 
 void
diff --git a/src/proxy/http/HttpTransact.cc b/src/proxy/http/HttpTransact.cc
index 76f72fd45f..f2a6308c21 100644
--- a/src/proxy/http/HttpTransact.cc
+++ b/src/proxy/http/HttpTransact.cc
@@ -1022,7 +1022,7 @@ HttpTransact::StartRemapRequest(State *s)
     TxnDbg(dbg_ctl_http_trans, "Before Remapping:");
     obj_describe(s->hdr_info.client_request.m_http, true);
   }
-  DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.client_request, s->state_machine_id(), "Incoming Request");
+  dump_header(dbg_ctl_http_hdrs, &s->hdr_info.client_request, s->state_machine_id(), "Incoming Request");
 
   if (s->http_config_param->referer_filter_enabled) {
     s->filter_mask = URL_REMAP_FILTER_REFERER;
@@ -2264,9 +2264,9 @@ HttpTransact::HandlePushResponseHdr(State *s)
   s->hdr_info.server_request.method_set(HTTP_METHOD_GET, HTTP_LEN_GET);
   s->hdr_info.server_request.value_set("X-Inktomi-Source", 16, "http PUSH", 9);
 
-  DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.server_response, s->state_machine_id(), "Pushed Response Header");
+  dump_header(dbg_ctl_http_hdrs, &s->hdr_info.server_response, s->state_machine_id(), "Pushed Response Header");
 
-  DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.server_request, s->state_machine_id(), "Generated Request Header");
+  dump_header(dbg_ctl_http_hdrs, &s->hdr_info.server_request, s->state_machine_id(), "Generated Request Header");
 
   s->response_received_time = s->request_sent_time = ink_local_time();
 
@@ -2447,7 +2447,7 @@ HttpTransact::issue_revalidate(State *s)
     // the client has the right credentials
     // this cache action is just to get us into the hcoofsr function
     s->cache_info.action = CACHE_DO_UPDATE;
-    DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.server_request, s->state_machine_id(), "Proxy's Request (Conditionalized)");
+    dump_header(dbg_ctl_http_hdrs, &s->hdr_info.server_request, s->state_machine_id(), "Proxy's Request (Conditionalized)");
     return;
   }
 
@@ -2520,7 +2520,7 @@ HttpTransact::issue_revalidate(State *s)
       if (str) {
         s->hdr_info.server_request.value_set(MIME_FIELD_IF_MODIFIED_SINCE, MIME_LEN_IF_MODIFIED_SINCE, str, length);
       }
-      DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.server_request, s->state_machine_id(), "Proxy's Request (Conditionalized)");
+      dump_header(dbg_ctl_http_hdrs, &s->hdr_info.server_request, s->state_machine_id(), "Proxy's Request (Conditionalized)");
     }
     // if Etag exists, also add if-non-match header
     if (c_resp->presence(MIME_PRESENCE_ETAG) && (s->hdr_info.server_request.method_get_wksidx() == HTTP_WKSIDX_GET ||
@@ -2534,7 +2534,7 @@ HttpTransact::issue_revalidate(State *s)
         }
         s->hdr_info.server_request.value_set(MIME_FIELD_IF_NONE_MATCH, MIME_LEN_IF_NONE_MATCH, etag, length);
       }
-      DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.server_request, s->state_machine_id(), "Proxy's Request (Conditionalized)");
+      dump_header(dbg_ctl_http_hdrs, &s->hdr_info.server_request, s->state_machine_id(), "Proxy's Request (Conditionalized)");
     }
     break;
   case HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION: // 203
@@ -3430,7 +3430,7 @@ HttpTransact::HandleResponse(State *s)
   s->current.now = s->response_received_time;
 
   TxnDbg(dbg_ctl_http_trans, "response_received_time: %" PRId64, (int64_t)s->response_received_time);
-  DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.server_response, s->state_machine_id(), "Incoming O.S. Response");
+  dump_header(dbg_ctl_http_hdrs, &s->hdr_info.server_response, s->state_machine_id(), "Incoming O.S. Response");
 
   Metrics::Counter::increment(http_rsb.incoming_responses);
 
@@ -4074,7 +4074,7 @@ HttpTransact::build_response_copy(State *s, HTTPHdr *base_response, HTTPHdr *out
   HttpTransactHeaders::convert_response(outgoing_version, outgoing_response); // http version conversion
   HttpTransactHeaders::add_server_header_to_response(s->txn_conf, outgoing_response);
 
-  DUMP_HEADER(dbg_ctl_http_hdrs, outgoing_response, s->state_machine_id(), "Proxy's Response");
+  dump_header(dbg_ctl_http_hdrs, outgoing_response, s->state_machine_id(), "Proxy's Response");
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -4616,7 +4616,7 @@ HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
                                                  warn_text, strlen(warn_text));
     }
 
-    DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.client_response, s->state_machine_id(), "Proxy's Response (Client Conditionals)");
+    dump_header(dbg_ctl_http_hdrs, &s->hdr_info.client_response, s->state_machine_id(), "Proxy's Response (Client Conditionals)");
     return;
   }
   // all other responses (not 304, 412, 416) are handled here
@@ -4839,7 +4839,7 @@ HttpTransact::handle_transform_ready(State *s)
   s->pre_transform_source = s->source;
   s->source               = SOURCE_TRANSFORM;
 
-  DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.transform_response, s->state_machine_id(), "Header From Transform");
+  dump_header(dbg_ctl_http_hdrs, &s->hdr_info.transform_response, s->state_machine_id(), "Header From Transform");
 
   build_response(s, &s->hdr_info.transform_response, &s->hdr_info.client_response, s->client_info.http_version);
 
@@ -4887,7 +4887,7 @@ HttpTransact::set_header_for_transform(State *s, HTTPHdr *base_header)
   //   in the chain
   s->hdr_info.transform_response.field_delete(MIME_FIELD_CONTENT_LENGTH, MIME_LEN_CONTENT_LENGTH);
 
-  DUMP_HEADER(dbg_ctl_http_hdrs, &s->hdr_info.transform_response, s->state_machine_id(), "Header To Transform");
+  dump_header(dbg_ctl_http_hdrs, &s->hdr_info.transform_response, s->state_machine_id(), "Header To Transform");
 }
 
 void
@@ -4947,7 +4947,7 @@ HttpTransact::set_headers_for_cache_write(State *s, HTTPInfo *cache_info, HTTPHd
     cache_info->response_get()->field_delete(MIME_FIELD_WWW_AUTHENTICATE, MIME_LEN_WWW_AUTHENTICATE);
   }
 
-  DUMP_HEADER(dbg_ctl_http_hdrs, cache_info->request_get(), s->state_machine_id(), "Cached Request Hdr");
+  dump_header(dbg_ctl_http_hdrs, cache_info->request_get(), s->state_machine_id(), "Cached Request Hdr");
 }
 
 void
@@ -7770,7 +7770,7 @@ HttpTransact::build_request(State *s, HTTPHdr *base_request, HTTPHdr *outgoing_r
   ink_assert(s->request_sent_time >= s->response_received_time);
 
   TxnDbg(dbg_ctl_http_trans, "request_sent_time: %" PRId64, (int64_t)s->request_sent_time);
-  DUMP_HEADER(dbg_ctl_http_hdrs, outgoing_request, s->state_machine_id(), "Proxy's Request");
+  dump_header(dbg_ctl_http_hdrs, outgoing_request, s->state_machine_id(), "Proxy's Request");
 
   Metrics::Counter::increment(http_rsb.outgoing_requests);
 }
@@ -7943,10 +7943,10 @@ HttpTransact::build_response(State *s, HTTPHdr *base_response, HTTPHdr *outgoing
 
   if (dbg_ctl_http_hdrs.on()) {
     if (base_response) {
-      DUMP_HEADER(dbg_ctl_http_hdrs, base_response, s->state_machine_id(), "Base Header for Building Response");
+      dump_header(dbg_ctl_http_hdrs, base_response, s->state_machine_id(), "Base Header for Building Response");
     }
 
-    DUMP_HEADER(dbg_ctl_http_hdrs, outgoing_response, s->state_machine_id(), "Proxy's Response 2");
+    dump_header(dbg_ctl_http_hdrs, outgoing_response, s->state_machine_id(), "Proxy's Response 2");
   }
 
   return;


(trafficserver) 02/06: txn_box: Address use after free in Do_upstream_rsp_body (#11428)

Posted by cm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4aa496ad9b1e0e62fd8b04adfc3f98c74fecbf76
Author: Brian Neradt <br...@gmail.com>
AuthorDate: Tue Jun 11 09:35:11 2024 -0500

    txn_box: Address use after free in Do_upstream_rsp_body (#11428)
    
    ASan reported a use-after-free in Do_upstream_rsp_body. This adds
    clearing the Continuation's data of the State member upon destruction
    because any use of it will be a use after free by definition.
    
    ```
    =================================================================
    ==764533==ERROR: AddressSanitizer: heap-use-after-free on address 0x62d006090610 at pc 0x7f5702f4d0d2 bp 0x7f5833a15ca0 sp 0x7f5833a15c90
    READ of size 8 at 0x62d006090610 thread T24 ([ET_NET 22])
        #0 0x7f5702f4d0d1 in operator() /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/plugins/experimental/txn_box/plugin/src/Machinery.cc:2579
        #1 0x7f5702f4d0d1 in _FUN /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/plugins/experimental/txn_box/plugin/src/Machinery.cc:2591
        #2 0x1251b2a in INKContInternal::handle_event(int, void*) /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/api/InkContInternal.cc:153
        #3 0x116b304 in Continuation::handleEvent(int, void*) /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/include/iocore/eventsystem/Continuation.h:228
        #4 0x116b304 in Continuation::handleEvent(int, void*) /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/include/iocore/eventsystem/Continuation.h:224
        #5 0x116b304 in EThread::process_event(Event*, int) /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/UnixEThread.cc:162
        #6 0x116d132 in EThread::process_queue(Queue<Event, Event::Link_link>*, int*, int*) /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/UnixEThread.cc:197
        #7 0x116e07f in EThread::execute_regular() /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/UnixEThread.cc:255
        #8 0x116f7d8 in EThread::execute() /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/UnixEThread.cc:348
        #9 0x116f7d8 in EThread::execute() /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/UnixEThread.cc:326
        #10 0x11684e7 in spawn_thread_internal /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/Thread.cc:75
        #11 0x7f58493031c9 in start_thread (/lib64/libpthread.so.0+0x81c9) (BuildId: e08f397aa6b7de799209cd5bc35aabe0496678f1)
        #12 0x7f5848f6fe72 in __clone (/lib64/libc.so.6+0x39e72) (BuildId: 574d156ec0c828321a4038189fc1cfe74d0bb2ec)
    
    0x62d006090610 is located 528 bytes inside of 32752-byte region [0x62d006090400,0x62d0060983f0)
    freed by thread T24 ([ET_NET 22]) here:
        #0 0x7f584aa05170 in __interceptor_free.part.0 (/lib64/libasan.so.8+0xdc170) (BuildId: 71dbf393857c775be459ab5583ba7b5fcbd9c884)
        #1 0x7f5849b71665 in swoc::_1_5_12::MemArena::Block::operator delete(void*) _sdk/release_posix-x86_64_gcc_12/libswoc_1.5.12/include/swoc/MemArena.h:646
        #2 0x7f5849b71665 in swoc::_1_5_12::MemArena::~MemArena() _scm/libswoc/code/src/MemArena.cc:276
    
    previously allocated by thread T24 ([ET_NET 22]) here:
        #0 0x7f584aa0662f in malloc (/lib64/libasan.so.8+0xdd62f) (BuildId: 71dbf393857c775be459ab5583ba7b5fcbd9c884)
        #1 0x7f5849b718ab in swoc::_1_5_12::MemArena::make_block(unsigned long) _scm/libswoc/code/src/MemArena.cc:99
    
    Thread T24 ([ET_NET 22]) created by T0 ([TS_MAIN]) here:
        #0 0x7f584a971ea5 in __interceptor_pthread_create (/lib64/libasan.so.8+0x48ea5) (BuildId: 71dbf393857c775be459ab5583ba7b5fcbd9c884)
        #1 0x1168c0c in ink_thread_create /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/include/tscore/ink_thread.h:129
        #2 0x1168c0c in Thread::start(char const*, void*, unsigned long, std::function<void ()> const&) /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/Thread.cc:92
        #3 0x117a904 in EventProcessor::spawn_event_threads(int, int, unsigned long) /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/UnixEventProcessor.cc:467
        #4 0x117b75a in EventProcessor::start(int, unsigned long) /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/iocore/eventsystem/UnixEventProcessor.cc:548
        #5 0x56dc74 in main /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/src/traffic_server/traffic_server.cc:2104
        #6 0x7f5848f70d84 in __libc_start_main (/lib64/libc.so.6+0x3ad84) (BuildId: 574d156ec0c828321a4038189fc1cfe74d0bb2ec)
    
    SUMMARY: AddressSanitizer: heap-use-after-free /sd/workspace/src/git.ouryahoo.com/Edge/build/_scm/trafficserver10.0_asan/plugins/experimental/txn_box/plugin/src/Machinery.cc:2579 in operator()
    Shadow bytes around the buggy address:
      0x62d006090380: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x62d006090400: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x62d006090480: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x62d006090500: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x62d006090580: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    =>0x62d006090600: fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x62d006090680: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x62d006090700: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x62d006090780: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x62d006090800: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x62d006090880: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    Shadow byte legend (one shadow byte represents 8 application bytes):
      Addressable:           00
      Partially addressable: 01 02 03 04 05 06 07
      Heap left redzone:       fa
      Freed heap region:       fd
      Stack left redzone:      f1
      Stack mid redzone:       f2
      Stack right redzone:     f3
      Stack after return:      f5
      Stack use after scope:   f8
      Global redzone:          f9
      Global init order:       f6
      Poisoned by user:        f7
      Container overflow:      fc
      Array cookie:            ac
      Intra object redzone:    bb
      ASan internal:           fe
      Left alloca redzone:     ca
      Right alloca redzone:    cb
    ==764533==ABORTING
    ```
    
    (cherry picked from commit 69e1c94db9f47d597ed61f09419b46e0aad3a7bb)
---
 plugins/experimental/txn_box/plugin/src/Machinery.cc | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/plugins/experimental/txn_box/plugin/src/Machinery.cc b/plugins/experimental/txn_box/plugin/src/Machinery.cc
index 7685f6a241..758173c499 100644
--- a/plugins/experimental/txn_box/plugin/src/Machinery.cc
+++ b/plugins/experimental/txn_box/plugin/src/Machinery.cc
@@ -2538,9 +2538,13 @@ Do_upstream_rsp_body::invoke(Context &ctx)
   struct State {
     TextView   _view;                ///< Source view for body.
     TSIOBuffer _tsio_buff = nullptr; ///< Buffer used to write body.
+    TSCont     _cont      = nullptr; ///< Transform continuation with which State is associated.
     /// Clean up the @c IOBuffer.
     ~State()
     {
+      if (_cont != nullptr) {
+        TSContDataSet(_cont, nullptr);
+      }
       if (_tsio_buff) {
         TSIOBufferDestroy(_tsio_buff);
       }
@@ -2550,6 +2554,10 @@ Do_upstream_rsp_body::invoke(Context &ctx)
   auto static transform = [](TSCont contp, TSEvent ev_code, void *) -> int {
     if (TSVConnClosedGet(contp)) {
       // IOBuffer is cleaned up at transaction close, not here.
+      if (auto state = static_cast<State *>(TSContDataGet(contp)); state) {
+        state->_cont = nullptr;
+        TSContDataSet(contp, nullptr);
+      }
       TSContDestroy(contp);
       return 0;
     }
@@ -2614,6 +2622,7 @@ Do_upstream_rsp_body::invoke(Context &ctx)
     auto state = ctx.make<State>();
     ctx.mark_for_cleanup(state);
     auto cont    = TSTransformCreate(transform, ctx._txn);
+    state->_cont = cont;
     state->_view = *content;
     TSContDataSet(cont, state);
     TSHttpTxnHookAdd(ctx._txn, TS_HTTP_RESPONSE_TRANSFORM_HOOK, cont);


(trafficserver) 04/06: Fix building without HWLOC (#11435)

Posted by cm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c55a9cdbf309e8c16c037ab38eebec71a6677009
Author: JosiahWI <41...@users.noreply.github.com>
AuthorDate: Mon Jun 10 13:15:57 2024 -0500

    Fix building without HWLOC (#11435)
    
    Fixes #11434.
    
    (cherry picked from commit 44a41cb5d7561f1ddd12172f144c7fce2269604f)
---
 src/iocore/net/Connection.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/iocore/net/Connection.cc b/src/iocore/net/Connection.cc
index 8af918dd75..3c2769591c 100644
--- a/src/iocore/net/Connection.cc
+++ b/src/iocore/net/Connection.cc
@@ -250,7 +250,7 @@ Server::setup_fd_for_listen(bool non_blocking, const NetProcessor::AcceptOptions
     int      cpu     = 0;
     EThread *ethread = this_ethread();
 
-#ifdef TS_USE_HWLOC
+#if TS_USE_HWLOC
     cpu = ethread->hwloc_obj->os_index;
 #else
     cpu = ethread->id;


(trafficserver) 01/06: Pass unused length parameter in HeaderField::append function (#11401)

Posted by cm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6fb27c0b7384980ac077e0264285c6ee0cad31ed
Author: Pavel Vazharov <pa...@x3me.net>
AuthorDate: Tue Jun 11 01:34:26 2024 +0300

    Pass unused length parameter in HeaderField::append function (#11401)
    
    The parameter is passed to the TSMimeHdrFieldValueStringInsert instead
    of the current -1.
    The latter causes `strlen(value)` instead `length` bytes to be inserted
    
    (cherry picked from commit 2501e4bc5e74a9fbb6290a6c1c92a727ba850dff)
---
 src/tscpp/api/Headers.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tscpp/api/Headers.cc b/src/tscpp/api/Headers.cc
index 789cf4dc8b..e755e6b535 100644
--- a/src/tscpp/api/Headers.cc
+++ b/src/tscpp/api/Headers.cc
@@ -310,7 +310,7 @@ bool
 HeaderField::append(const char *value, int length)
 {
   return (TSMimeHdrFieldValueStringInsert(iter_.state_->mloc_container_->hdr_buf_, iter_.state_->mloc_container_->hdr_loc_,
-                                          iter_.state_->mloc_container_->field_loc_, -1, value, -1) == TS_SUCCESS);
+                                          iter_.state_->mloc_container_->field_loc_, -1, value, length) == TS_SUCCESS);
 }
 
 bool


(trafficserver) 03/06: support full range of unsigned char for hex conversion. (#11429)

Posted by cm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d8a856cf47dc7b9c97eafc4424700eb17ecefae9
Author: Chris McFarlen <ch...@mcfarlen.us>
AuthorDate: Tue Jun 11 12:50:44 2024 -0500

    support full range of unsigned char for hex conversion.   (#11429)
    
    * support full range of unsigned char for hex conversion.  Install StringConvert.h
    
    * test round trip for unsigned strings
    
    * interpret as unsigned char to avoid out of range
    
    (cherry picked from commit 348aedf77c2c19a3a2269c13aceced4d4f53e512)
---
 include/tsutil/StringConvert.h              | 12 ++++++++----
 src/tsutil/CMakeLists.txt                   |  1 +
 src/tsutil/unit_tests/test_StringConvert.cc | 12 ++++++++++++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/include/tsutil/StringConvert.h b/include/tsutil/StringConvert.h
index 3465b5c7da..a4339aeeb7 100644
--- a/include/tsutil/StringConvert.h
+++ b/include/tsutil/StringConvert.h
@@ -44,9 +44,13 @@ hex(const std::string_view input)
 
   result.resize(input.size() * 2);
 
-  char *p = result.data();
-  for (auto x : input) {
-    if (auto [ptr, err] = std::to_chars(p, result.data() + result.size(), x, 16); err == std::errc()) {
+  char *p   = result.data();
+  char *end = result.data() + result.size();
+  for (unsigned char x : input) {
+    if (x < 0x10) {
+      *p++ = '0';
+    }
+    if (auto [ptr, err] = std::to_chars(p, end, x, 16); err == std::errc()) {
       p = ptr;
     } else {
       throw std::runtime_error(std::make_error_code(err).message().c_str());
@@ -80,7 +84,7 @@ unhex(const std::string_view input)
 
   const char *p = input.data();
   for (auto &x : result) {
-    if (auto [ptr, err] = std::from_chars(p, p + 2, x, 16); err == std::errc()) {
+    if (auto [ptr, err] = std::from_chars(p, p + 2, reinterpret_cast<unsigned char &>(x), 16); err == std::errc()) {
       p = ptr;
     } else {
       throw std::runtime_error(std::make_error_code(err).message().c_str());
diff --git a/src/tsutil/CMakeLists.txt b/src/tsutil/CMakeLists.txt
index d018301f0c..dadf7564bd 100644
--- a/src/tsutil/CMakeLists.txt
+++ b/src/tsutil/CMakeLists.txt
@@ -30,6 +30,7 @@ set(TSUTIL_PUBLIC_HEADERS
     ${PROJECT_SOURCE_DIR}/include/tsutil/LocalBuffer.h
     ${PROJECT_SOURCE_DIR}/include/tsutil/PostScript.h
     ${PROJECT_SOURCE_DIR}/include/tsutil/Strerror.h
+    ${PROJECT_SOURCE_DIR}/include/tsutil/StringConvert.h
     ${PROJECT_SOURCE_DIR}/include/tsutil/Regex.h
     ${PROJECT_SOURCE_DIR}/include/tsutil/TsSharedMutex.h
     ${PROJECT_SOURCE_DIR}/include/tsutil/YamlCfg.h
diff --git a/src/tsutil/unit_tests/test_StringConvert.cc b/src/tsutil/unit_tests/test_StringConvert.cc
index 06f708b513..2ee1bba5ae 100644
--- a/src/tsutil/unit_tests/test_StringConvert.cc
+++ b/src/tsutil/unit_tests/test_StringConvert.cc
@@ -25,9 +25,21 @@
 
 #include <tsutil/StringConvert.h>
 
+std::string
+mkunsigned_string()
+{
+  const char data[] = {static_cast<char>(0xab), static_cast<char>(0x9e), static_cast<char>(0xff), 0x12, 0x04};
+
+  return std::string(data, 5);
+}
+
 TEST_CASE("StringConvert", "[STE]")
 {
   REQUIRE(ts::hex("01") == "3031");
   REQUIRE(ts::unhex("3031") == "01");
   REQUIRE(ts::hex("5pn2QM") == "35706e32514d");
+
+  auto usgn = mkunsigned_string();
+  REQUIRE(ts::hex(usgn) == "ab9eff1204");
+  REQUIRE(ts::unhex(ts::hex(usgn)) == usgn);
 }