You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2019/04/30 16:23:30 UTC

[trafficserver] branch master updated: MIMEScanner: only clear m_line buffer if at MIME_PARSE_BEFORE state

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

zwoop 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 5be0134  MIMEScanner: only clear m_line buffer if at MIME_PARSE_BEFORE state
5be0134 is described below

commit 5be013418a71a85d0b5dba2c956be75a9942526b
Author: Brian Olsen <br...@comcast.com>
AuthorDate: Thu Apr 18 18:02:26 2019 +0000

    MIMEScanner: only clear m_line buffer if at MIME_PARSE_BEFORE state
---
 proxy/hdrs/MIME.cc                 |  4 ++--
 proxy/hdrs/unit_tests/test_Hdrs.cc | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/proxy/hdrs/MIME.cc b/proxy/hdrs/MIME.cc
index c23e264..73d5b2b 100644
--- a/proxy/hdrs/MIME.cc
+++ b/proxy/hdrs/MIME.cc
@@ -2334,6 +2334,7 @@ MIMEScanner::get(TextView &input, TextView &output, bool &output_shares_input, b
   while (PARSE_RESULT_CONT == zret && !text.empty()) {
     switch (m_state) {
     case MIME_PARSE_BEFORE: // waiting to find a field.
+      m_line.resize(0);     // any caller should already be done with the buffer
       if (ParseRules::is_cr(*text)) {
         ++text;
         if (!text.empty() && ParseRules::is_lf(*text)) {
@@ -2445,8 +2446,7 @@ MIMEScanner::get(TextView &input, TextView &output, bool &output_shares_input, b
   output_shares_input = true;
   if (PARSE_RESULT_CONT != zret) {
     if (!m_line.empty()) {
-      output = m_line;
-      m_line.resize(0); // depending resize(0) not deallocating internal string memory.
+      output              = m_line; // cleared when called with state MIME_PARSE_BEFORE
       output_shares_input = false;
     } else {
       output = parsed_text;
diff --git a/proxy/hdrs/unit_tests/test_Hdrs.cc b/proxy/hdrs/unit_tests/test_Hdrs.cc
index 790418c..a471339 100644
--- a/proxy/hdrs/unit_tests/test_Hdrs.cc
+++ b/proxy/hdrs/unit_tests/test_Hdrs.cc
@@ -84,3 +84,34 @@ TEST_CASE("HdrTest", "[proxy][hdrtest]")
     req_hdr.destroy();
   }
 }
+
+TEST_CASE("MIMEScanner_fragments", "[proxy][mimescanner_fragments]")
+{
+  constexpr ts::TextView const message = "GET /index.html HTTP/1.0\r\n";
+
+  struct Fragment {
+    ts::TextView msg;
+    bool shares_input;
+    int expected_result;
+  };
+  constexpr std::array<Fragment, 3> const fragments = {{
+    {message.substr(0, 11), true, PARSE_RESULT_CONT},
+    {message.substr(11, 11), true, PARSE_RESULT_CONT},
+    {message.substr(22), false, PARSE_RESULT_OK},
+  }};
+
+  MIMEScanner scanner;
+  ts::TextView output; // only set on last call
+
+  for (auto const &frag : fragments) {
+    ts::TextView input          = frag.msg;
+    bool got_shares_input       = !frag.shares_input;
+    constexpr bool const is_eof = false;
+    ParseResult const got_res   = scanner.get(input, output, got_shares_input, is_eof, MIMEScanner::LINE);
+
+    REQUIRE(frag.expected_result == got_res);
+    REQUIRE(frag.shares_input == got_shares_input);
+  }
+
+  REQUIRE(message == output);
+}