Note: This patch is on the critical path.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 19 May 2008 20:07:20 +0000 (20:07 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 19 May 2008 20:07:20 +0000 (20:07 +0000)
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=42750
Making parsing of the request line tolerant of multiple SP and/or HT rather than requiring single SP characters.

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

java/org/apache/coyote/http11/InternalAprInputBuffer.java
java/org/apache/coyote/http11/InternalInputBuffer.java
java/org/apache/coyote/http11/InternalNioInputBuffer.java

index 4286458..f1137cf 100644 (file)
@@ -403,7 +403,8 @@ public class InternalAprInputBuffer implements InputBuffer {
                     throw new EOFException(sm.getString("iib.eof.error"));
             }
 
-            if (buf[pos] == Constants.SP) {
+            // Spec says single SP but it also says be tolerant of HT
+            if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
                 space = true;
                 request.method().setBytes(buf, start, pos - start);
             }
@@ -412,6 +413,20 @@ public class InternalAprInputBuffer implements InputBuffer {
 
         }
 
+        // Spec says single SP but also says be tolerant of multiple and/or HT
+        while (space) {
+            // Read new bytes if needed
+            if (pos >= lastValid) {
+                if (!fill())
+                    throw new EOFException(sm.getString("iib.eof.error"));
+            }
+            if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+                pos++;
+            } else {
+                space = false;
+            }
+        }
+
         // Mark the current buffer position
         start = pos;
         int end = 0;
@@ -421,7 +436,6 @@ public class InternalAprInputBuffer implements InputBuffer {
         // Reading the URI
         //
 
-        space = false;
         boolean eol = false;
 
         while (!space) {
@@ -432,7 +446,8 @@ public class InternalAprInputBuffer implements InputBuffer {
                     throw new EOFException(sm.getString("iib.eof.error"));
             }
 
-            if (buf[pos] == Constants.SP) {
+            // Spec says single SP but it also says be tolerant of HT
+            if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
                 space = true;
                 end = pos;
             } else if ((buf[pos] == Constants.CR) 
@@ -459,6 +474,21 @@ public class InternalAprInputBuffer implements InputBuffer {
             request.requestURI().setBytes(buf, start, end - start);
         }
 
+        // Spec says single SP but also says be tolerant of multiple and/or HT
+        while (space) {
+            // Read new bytes if needed
+            if (pos >= lastValid) {
+                if (!fill())
+                    throw new EOFException(sm.getString("iib.eof.error"));
+            }
+            if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+                pos++;
+            } else {
+                space = false;
+            }
+        }
+
+
         // Mark the current buffer position
         start = pos;
         end = 0;
index 6b77f24..d98a64b 100644 (file)
@@ -391,7 +391,8 @@ public class InternalInputBuffer implements InputBuffer {
                     throw new EOFException(sm.getString("iib.eof.error"));
             }
 
-            if (buf[pos] == Constants.SP) {
+            // Spec says single SP but it also says be tolerant of HT
+            if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
                 space = true;
                 request.method().setBytes(buf, start, pos - start);
             }
@@ -400,6 +401,21 @@ public class InternalInputBuffer implements InputBuffer {
 
         }
 
+        
+        // Spec says single SP but also says be tolerant of multiple and/or HT
+        while (space) {
+            // Read new bytes if needed
+            if (pos >= lastValid) {
+                if (!fill())
+                    throw new EOFException(sm.getString("iib.eof.error"));
+            }
+            if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+                pos++;
+            } else {
+                space = false;
+            }
+        }
+
         // Mark the current buffer position
         start = pos;
         int end = 0;
@@ -409,7 +425,6 @@ public class InternalInputBuffer implements InputBuffer {
         // Reading the URI
         //
 
-        space = false;
         boolean eol = false;
 
         while (!space) {
@@ -420,7 +435,8 @@ public class InternalInputBuffer implements InputBuffer {
                     throw new EOFException(sm.getString("iib.eof.error"));
             }
 
-            if (buf[pos] == Constants.SP) {
+            // Spec says single SP but it also says be tolerant of HT
+            if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
                 space = true;
                 end = pos;
             } else if ((buf[pos] == Constants.CR) 
@@ -447,6 +463,20 @@ public class InternalInputBuffer implements InputBuffer {
             request.requestURI().setBytes(buf, start, end - start);
         }
 
+        // Spec says single SP but also says be tolerant of multiple and/or HT
+        while (space) {
+            // Read new bytes if needed
+            if (pos >= lastValid) {
+                if (!fill())
+                    throw new EOFException(sm.getString("iib.eof.error"));
+            }
+            if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+                pos++;
+            } else {
+                space = false;
+            }
+        }
+
         // Mark the current buffer position
         start = pos;
         end = 0;
index a0ac5bd..d57d214 100644 (file)
@@ -454,7 +454,7 @@ public class InternalNioInputBuffer implements InputBuffer {
                     if (!fill(true, false)) //request line parsing
                         return false;
                 }
-                if (buf[pos] == Constants.SP) {
+                if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
                     space = true;
                     request.method().setBytes(buf, parsingRequestLineStart, pos - parsingRequestLineStart);
                 }
@@ -464,20 +464,34 @@ public class InternalNioInputBuffer implements InputBuffer {
             parsingRequestLinePhase = 3;
         }
         if ( parsingRequestLinePhase == 3 ) {
+            // Spec says single SP but also be tolerant of multiple and/or HT
+            boolean space = true;
+            while (space) {
+                // Read new bytes if needed
+                if (pos >= lastValid) {
+                    if (!fill(true, false)) //request line parsing
+                        return false;
+                }
+                if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+                    pos++;
+                } else {
+                    space = false;
+                }
+            }
+
             // Mark the current buffer position
             
             int end = 0;
             //
             // Reading the URI
             //
-            boolean space = false;
             while (!space) {
                 // Read new bytes if needed
                 if (pos >= lastValid) {
                     if (!fill(true,false)) //request line parsing
                         return false;
                 }
-                if (buf[pos] == Constants.SP) {
+                if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
                     space = true;
                     end = pos;
                 } else if ((buf[pos] == Constants.CR) 
@@ -504,6 +518,21 @@ public class InternalNioInputBuffer implements InputBuffer {
             parsingRequestLinePhase = 4;
         }
         if ( parsingRequestLinePhase == 4 ) {
+            // Spec says single SP but also be tolerant of multiple and/or HT
+            boolean space = true;
+            while (space) {
+                // Read new bytes if needed
+                if (pos >= lastValid) {
+                    if (!fill(true, false)) //request line parsing
+                        return false;
+                }
+                if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+                    pos++;
+                } else {
+                    space = false;
+                }
+            }
+
             // Mark the current buffer position
             
             end = 0;