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 5e39658f7c Tweak MimeHdr::get_host_port_values to not run over the end 
of the TextView. (#8468)
5e39658f7c is described below

commit 5e39658f7c0bc91613468c9513ba22ede1739d7e
Author: Alan M. Carroll <[email protected]>
AuthorDate: Tue Nov 2 11:47:09 2021 -0500

    Tweak MimeHdr::get_host_port_values to not run over the end of the 
TextView. (#8468)
    
    Fix for #8461
    
    (cherry picked from commit 055ca11c2842a64bf7df8d547515670e1a04afc1)
---
 proxy/hdrs/MIME.cc                         | 11 +++--------
 src/tscpp/util/unit_tests/test_TextView.cc | 11 +++--------
 2 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/proxy/hdrs/MIME.cc b/proxy/hdrs/MIME.cc
index 45c16c386d..0a55dd06b4 100644
--- a/proxy/hdrs/MIME.cc
+++ b/proxy/hdrs/MIME.cc
@@ -2284,20 +2284,15 @@ MIMEHdr::get_host_port_values(const char **host_ptr, 
///< Pointer to host.
     if (b) {
       if ('[' == *b) {
         auto idx = b.find(']');
-        if (idx <= b.size() && b[idx + 1] == ':') {
+        if (idx < b.size() - 1 && b[idx + 1] == ':') {
           host = b.take_prefix_at(idx + 1);
           port = b;
         } else {
           host = b;
         }
       } else {
-        auto x = b.split_prefix_at(':');
-        if (x) {
-          host = x;
-          port = b;
-        } else {
-          host = b;
-        }
+        host = b.take_prefix_at(':');
+        port = b;
       }
 
       if (host) {
diff --git a/src/tscpp/util/unit_tests/test_TextView.cc 
b/src/tscpp/util/unit_tests/test_TextView.cc
index 8f71e0aa39..7f36536908 100644
--- a/src/tscpp/util/unit_tests/test_TextView.cc
+++ b/src/tscpp/util/unit_tests/test_TextView.cc
@@ -275,20 +275,15 @@ TEST_CASE("TextView Affixes", "[libts][TextView]")
   auto f_host = [](TextView b, TextView &host, TextView &port) -> void {
     if ('[' == *b) {
       auto idx = b.find(']');
-      if (idx <= b.size() && b[idx + 1] == ':') {
+      if (idx < b.size() - 1 && b[idx + 1] == ':') {
         host = b.take_prefix_at(idx + 1);
         port = b;
       } else {
         host = b;
       }
     } else {
-      auto x = b.split_prefix_at(':');
-      if (x) {
-        host = x;
-        port = b;
-      } else {
-        host = b;
-      }
+      host = b.take_prefix_at(':');
+      port = b;
     }
   };
 

Reply via email to