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

shinrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new f202f84  Fixing a previous fix to fully allocate strings when heap 
mismatch detected.
f202f84 is described below

commit f202f8497f4a854b17a9711ad51559c5c89642ea
Author: Susan Hinrichs <[email protected]>
AuthorDate: Tue Mar 5 17:12:00 2019 +0000

    Fixing a previous fix to fully allocate strings when heap mismatch detected.
---
 proxy/hdrs/HTTP.cc   |  2 +-
 proxy/hdrs/HdrHeap.h | 20 ++++++++++++++++++++
 proxy/hdrs/URL.cc    | 15 +++++++++++++++
 proxy/hdrs/URL.h     |  1 +
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/proxy/hdrs/HTTP.cc b/proxy/hdrs/HTTP.cc
index eebf4ad..74e79df 100644
--- a/proxy/hdrs/HTTP.cc
+++ b/proxy/hdrs/HTTP.cc
@@ -708,7 +708,7 @@ http_hdr_url_set(HdrHeap *heap, HTTPHdrImpl *hh, URLImpl 
*url)
         int url_string_length   = url->strings_length();
         heap->m_read_write_heap = new_HdrStrHeap(url_string_length);
       }
-      hh->u.req.m_url_impl->move_strings(heap->m_read_write_heap.get());
+      hh->u.req.m_url_impl->rehome_strings(heap);
     } else {
       hh->u.req.m_url_impl = url;
     }
diff --git a/proxy/hdrs/HdrHeap.h b/proxy/hdrs/HdrHeap.h
index 9811362..1435f4b 100644
--- a/proxy/hdrs/HdrHeap.h
+++ b/proxy/hdrs/HdrHeap.h
@@ -235,6 +235,26 @@ public:
     }
   }
 
+  // Working function to copy strings into a new heap
+  // Unlike the HDR_MOVE_STR macro, this function will call
+  // allocate_str which will update the new_heap to create more space
+  // if there is not originally sufficient space
+  inline std::string_view
+  localize(const std::string_view &string)
+  {
+    auto length = string.length();
+    if (length > 0) {
+      char *new_str = this->allocate_str(length);
+      if (new_str) {
+        memcpy(new_str, string.data(), length);
+      } else {
+        length = 0;
+      }
+      return {new_str, length};
+    }
+    return {nullptr, 0};
+  }
+
   // Sanity Check Functions
   void sanity_check_strs();
   bool check_marshalled(uint32_t buf_length);
diff --git a/proxy/hdrs/URL.cc b/proxy/hdrs/URL.cc
index dccc527..6137add 100644
--- a/proxy/hdrs/URL.cc
+++ b/proxy/hdrs/URL.cc
@@ -349,6 +349,21 @@ URLImpl::unmarshal(intptr_t offset)
 }
 
 void
+URLImpl::rehome_strings(HdrHeap *new_heap)
+{
+  m_ptr_scheme         = new_heap->localize({m_ptr_scheme, 
m_len_scheme}).data();
+  m_ptr_user           = new_heap->localize({m_ptr_user, m_len_user}).data();
+  m_ptr_password       = new_heap->localize({m_ptr_password, 
m_len_password}).data();
+  m_ptr_host           = new_heap->localize({m_ptr_host, m_len_host}).data();
+  m_ptr_port           = new_heap->localize({m_ptr_port, m_len_port}).data();
+  m_ptr_path           = new_heap->localize({m_ptr_path, m_len_path}).data();
+  m_ptr_params         = new_heap->localize({m_ptr_params, 
m_len_params}).data();
+  m_ptr_query          = new_heap->localize({m_ptr_query, m_len_query}).data();
+  m_ptr_fragment       = new_heap->localize({m_ptr_fragment, 
m_len_fragment}).data();
+  m_ptr_printed_string = new_heap->localize({m_ptr_printed_string, 
m_len_printed_string}).data();
+}
+
+void
 URLImpl::move_strings(HdrStrHeap *new_heap)
 {
   HDR_MOVE_STR(m_ptr_scheme, m_len_scheme);
diff --git a/proxy/hdrs/URL.h b/proxy/hdrs/URL.h
index 1524a5a..a98d24c 100644
--- a/proxy/hdrs/URL.h
+++ b/proxy/hdrs/URL.h
@@ -80,6 +80,7 @@ struct URLImpl : public HdrHeapObjImpl {
   int marshal(MarshalXlate *str_xlate, int num_xlate);
   void unmarshal(intptr_t offset);
   void move_strings(HdrStrHeap *new_heap);
+  void rehome_strings(HdrHeap *new_heap);
   size_t strings_length();
 
   // Sanity Check Functions

Reply via email to