You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by so...@apache.org on 2017/07/26 23:56:43 UTC

[trafficserver] 01/02: TS-4930: Unfolds request headers that are using obs continuations

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

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

commit f4312c5c9049d2a2e6d1a8b504534d598abc3a85
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Tue Oct 4 11:22:05 2016 -0600

    TS-4930: Unfolds request headers that are using obs continuations
    
    (cherry picked from commit da4a9f6ed21fb0f0694a9bc1e0ae4a616d23f610)
    
     Conflicts:
    	proxy/hdrs/HdrTest.cc
---
 proxy/hdrs/HdrTest.cc | 68 ++++++++++++++++++++++++++++++++++-----------------
 proxy/hdrs/MIME.cc    |  6 +++++
 2 files changed, 52 insertions(+), 22 deletions(-)

diff --git a/proxy/hdrs/HdrTest.cc b/proxy/hdrs/HdrTest.cc
index 9a75b33..7cb4198 100644
--- a/proxy/hdrs/HdrTest.cc
+++ b/proxy/hdrs/HdrTest.cc
@@ -462,27 +462,31 @@ HdrTest::test_url()
 int
 HdrTest::test_mime()
 {
-  static const char mime[] = {//        "Date: Tuesday, 08-Dec-98 20:32:17 GMT\r\n"
-                              "Date: 6 Nov 1994 08:49:37 GMT\r\n"
-                              "Max-Forwards: 65535\r\n"
-                              "Cache-Control: private\r\n"
-                              "accept: foo\r\n"
-                              "accept: bar\n"
-                              ": (null) field name\r\n"
-                              "aCCept: \n"
-                              "ACCEPT\r\n"
-                              "foo: bar\r\n"
-                              "foo: argh\r\n"
-                              "foo: three, four\r\n"
-                              "word word: word \r\n"
-                              "accept: \"fazzle, dazzle\"\r\n"
-                              "accept: 1, 2, 3, 4, 5, 6, 7, 8\r\n"
-                              "continuation: part1\r\n"
-                              " part2\r\n"
-                              "scooby: doo\r\n"
-                              "scooby : doo\r\n"
-                              "bar: foo\r\n"
-                              "\r\n"};
+  // This can not be a static string (any more) since we unfold the headers
+  // in place.
+  char mime[] = {
+    //        "Date: Tuesday, 08-Dec-98 20:32:17 GMT\r\n"
+    "Date: 6 Nov 1994 08:49:37 GMT\r\n"
+    "Max-Forwards: 65535\r\n"
+    "Cache-Control: private\r\n"
+    "accept: foo\r\n"
+    "accept: bar\n"
+    ": (null) field name\r\n"
+    "aCCept: \n"
+    "ACCEPT\r\n"
+    "foo: bar\r\n"
+    "foo: argh\r\n"
+    "foo: three, four\r\n"
+    "word word: word \r\n"
+    "accept: \"fazzle, dazzle\"\r\n"
+    "accept: 1, 2, 3, 4, 5, 6, 7, 8\r\n"
+    "continuation: part1\r\n"
+    " part2\r\n"
+    "scooby: doo\r\n"
+    "scooby : doo\r\n"
+    "bar: foo\r\n"
+    "\r\n",
+  };
 
   int err;
   MIMEHdr hdr;
@@ -507,6 +511,26 @@ HdrTest::test_mime()
   if (err < 0)
     return (failures_to_status("test_mime", 1));
 
+  // Test the (new) continuation line folding to be correct. This should replace the
+  // \r\n with two spaces (so a total of three between "part1" and "part2").
+  int length;
+  const char *continuation = hdr.value_get("continuation", 12, &length);
+
+  if ((13 != length)) {
+    printf("FAILED: continue header folded line was too short\n");
+    return (failures_to_status("test_mime", 1));
+  }
+
+  if (strncmp(continuation + 5, "   ", 3)) {
+    printf("FAILED: continue header unfolding did not produce correct WS's\n");
+    return (failures_to_status("test_mime", 1));
+  }
+
+  if (strncmp(continuation, "part1   part2", 13)) {
+    printf("FAILED: continue header unfolding was not correct\n");
+    return (failures_to_status("test_mime", 1));
+  }
+
   hdr.field_delete("not_there", 9);
   hdr.field_delete("accept", 6);
   hdr.field_delete("scooby", 6);
@@ -523,7 +547,7 @@ HdrTest::test_mime()
 
   hdr.set_age(9999);
 
-  int length = hdr.length_get();
+  length = hdr.length_get();
   printf("hdr.length_get() = %d\n", length);
 
   time_t t0, t1, t2;
diff --git a/proxy/hdrs/MIME.cc b/proxy/hdrs/MIME.cc
index b4d4e36..4caf5fa 100644
--- a/proxy/hdrs/MIME.cc
+++ b/proxy/hdrs/MIME.cc
@@ -2379,6 +2379,12 @@ mime_scanner_get(MIMEScanner *S, const char **raw_input_s, const char *raw_input
     case MIME_PARSE_AFTER:
       // After a LF. Might be the end or a continuation.
       if (ParseRules::is_ws(*raw_input_c)) {
+        char *unfold = const_cast<char *>(raw_input_c - 1);
+
+        *unfold-- = ' ';
+        if (ParseRules::is_cr(*unfold)) {
+          *unfold = ' ';
+        }
         S->m_state = MIME_PARSE_INSIDE; // back inside the field.
       } else {
         S->m_state = MIME_PARSE_BEFORE; // field terminated.

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.