Author: markt Date: Mon May 19 13:07:20 2008 New Revision: 657954 URL: http://svn.apache.org/viewvc?rev=657954&view=rev Log: Note: This patch is on the critical path. 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.
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java?rev=657954&r1=657953&r2=657954&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java Mon May 19 13:07:20 2008 @@ -403,7 +403,8 @@ 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 @@ } + // 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 @@ // Reading the URI // - space = false; boolean eol = false; while (!space) { @@ -432,7 +446,8 @@ 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 @@ 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; Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java?rev=657954&r1=657953&r2=657954&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java Mon May 19 13:07:20 2008 @@ -391,7 +391,8 @@ 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 @@ } + + // 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 @@ // Reading the URI // - space = false; boolean eol = false; while (!space) { @@ -420,7 +435,8 @@ 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 @@ 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; Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=657954&r1=657953&r2=657954&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Mon May 19 13:07:20 2008 @@ -454,7 +454,7 @@ 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 @@ 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 @@ 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; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]