]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Support multiline quoted-string header fields
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Tue, 31 May 2011 21:06:39 +0000 (00:06 +0300)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Tue, 31 May 2011 21:06:39 +0000 (00:06 +0300)
Currently the httpHeaderParseQuotedString does not support multiline quoted
string fields. According the rfc2616 multiline quoted string fields should
supported:

   quoted-string  = ( <"> *(qdtext | quoted-pair ) <"> )
   qdtext         = <any TEXT except <">>
   TEXT           = <any OCTET except CTLs,
                        but including LWS>
   LWS            = [CRLF] 1*( SP | HT )

This patch replaces the "[\r]\n " or "[\r]\n\t" with a single space.

This is a Measurement Factory project

src/HttpHeaderTools.cc

index 8d7ba32709e88b2530f04198518e410163f69c3e..b5137c8647a48efeb8f182c9e0afb48c84f6f743 100644 (file)
@@ -336,25 +336,51 @@ httpHeaderParseQuotedString(const char *start, const int len, String *val)
     const char *end, *pos;
     val->clean();
     if (*start != '"') {
-        debugs(66, 2, "failed to parse a quoted-string header field near '" << start << "'");
+        debugs(66, 2, HERE << "failed to parse a quoted-string header field near '" << start << "'");
         return 0;
     }
     pos = start + 1;
 
     while (*pos != '"' && len > (pos-start)) {
+
+        if (*pos =='\r') {
+            pos++;
+            if ((pos-start) > len || *pos != '\n') {
+                debugs(66, 2, HERE << "failed to parse a quoted-string header field with '\\r' octet " << (start-pos)
+                       << " bytes into '" << start << "'");
+                val->clean();
+                return 0;
+            }
+        }
+
+        if (*pos == '\n') {
+            pos++;
+            if ( (pos-start) > len || (*pos != ' ' && *pos != '\t')) {
+                debugs(66, 2, HERE << "failed to parse multiline quoted-string header field '" << start << "'");
+                val->clean();
+                return 0;
+            }
+            // TODO: replace the entire LWS with a space
+            val->append(" ");
+            pos++;
+            debugs(66, 2, HERE << "len < pos-start => " << len << " < " << (pos-start));
+            continue;
+        }
+
         bool quoted = (*pos == '\\');
-        if (quoted)
+        if (quoted) {
             pos++;
-        if (!*pos || (pos-start) > len) {
-            debugs(66, 2, "failed to parse a quoted-string header field near '" << start << "'");
-            val->clean();
-            return 0;
+            if (!*pos || (pos-start) > len) {
+                debugs(66, 2, HERE << "failed to parse a quoted-string header field near '" << start << "'");
+                val->clean();
+                return 0;
+            }
         }
         end = pos;
-        while (end <= (start+len) && *end != '\\' && *end != '\"' && *end > 0x1F && *end != 0x7F)
+        while (end < (start+len) && *end != '\\' && *end != '\"' && *end > 0x1F && *end != 0x7F)
             end++;
-        if (*end <= 0x1F || *end == 0x7F) {
-            debugs(66, 2, "failed to parse a quoted-string header field with CTL octet " << (start-pos)
+        if ((*end <= 0x1F && *end != '\r' && *end != '\n') || *end == 0x7F) {
+            debugs(66, 2, HERE << "failed to parse a quoted-string header field with CTL octet " << (start-pos)
                    << " bytes into '" << start << "'");
             val->clean();
             return 0;
@@ -362,6 +388,12 @@ httpHeaderParseQuotedString(const char *start, const int len, String *val)
         val->append(pos, end-pos);
         pos = end;
     }
+
+    if (*pos != '\"') {
+        debugs(66, 2, HERE << "failed to parse a quoted-string header field which did not end with \" ");
+        val->clean();
+        return 0;
+    }
     /* Make sure it's defined even if empty "" */
     if (!val->defined())
         val->limitInit("", 0);