Followup for rev.892612
authorkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 21 Dec 2009 06:29:40 +0000 (06:29 +0000)
committerkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 21 Dec 2009 06:29:40 +0000 (06:29 +0000)
Better fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=47963
Tab character is also allowed in the reason-phrase
Also, use more traditional method of iterating over a string.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@892707 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/http/HttpMessages.java

index 9e56679..8abb5c1 100644 (file)
@@ -118,16 +118,21 @@ public class HttpMessages {
         if (msg == null) {
             return true;
         }
-        
-        // TEXT is defined as OCTET excpet CTLs
+
+        // Reason-Phrase is defined as *<TEXT, excluding CR, LF>
+        // TEXT is defined as any OCTET except CTLs, but including LWS
         // OCTET is defined as an 8-bit sequence of data
         // CTL is defined as octets 0-31 and 127
-        for (char c : msg.toCharArray()) {
-            if (c > 255 || c < 32 || c == 127) {
-                return false;
+        // LWS, if we exclude CR LF pairs, is defined as SP or HT (32, 9)
+        final int len = msg.length();
+        for (int i = 0; i < len; i++) {
+            char c = msg.charAt(i);
+            if (32 <= c && c <= 126 || 128 <= c && c <= 255 || c == 9) {
+                continue;
             }
+            return false;
         }
-        
+
         return true;
     }
 }