Author: markt Date: Tue May 28 11:32:00 2013 New Revision: 1486877 URL: http://svn.apache.org/r1486877 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54947 NIO connector incorrectly rejects a request if the CRLF terminating the request line is split across multiple packets. Patch for the fix by Konstantin Preißer. I added a test case.
Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1486875 Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=1486877&r1=1486876&r2=1486877&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Tue May 28 11:32:00 2013 @@ -339,11 +339,11 @@ public class InternalNioInputBuffer exte } parsingRequestLineStart = pos; parsingRequestLinePhase = 6; - } - if (parsingRequestLinePhase == 6) { + // Mark the current buffer position - end = 0; + } + if (parsingRequestLinePhase == 6) { // // Reading the protocol // Protocol is always US-ASCII Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java?rev=1486877&r1=1486876&r2=1486877&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java (original) +++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java Tue May 28 11:32:00 2013 @@ -42,7 +42,9 @@ public abstract class SimpleHttpClient { public static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); - public static final String CRLF = "\r\n"; + public static final String CR = "\r"; + public static final String LF = "\n"; + public static final String CRLF = CR + LF; public static final String INFO_100 = "HTTP/1.1 100"; public static final String OK_200 = "HTTP/1.1 200"; Modified: tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java?rev=1486877&r1=1486876&r2=1486877&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java (original) +++ tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java Tue May 28 11:32:00 2013 @@ -415,4 +415,67 @@ public class TestInternalInputBuffer ext } + /** + * Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=54947 + */ + @Test + public void testBug54947() { + + Bug54947Client client = new Bug54947Client(); + + client.doRequest(); + assertTrue(client.isResponse200()); + assertTrue(client.isResponseBodyOK()); + } + + + /** + * Bug 54947 test client. + */ + private class Bug54947Client extends SimpleHttpClient { + + private Exception doRequest() { + + Tomcat tomcat = getTomcatInstance(); + + Context root = tomcat.addContext("", TEMP_DIR); + Tomcat.addServlet(root, "Bug54947", new TesterServlet()); + root.addServletMapping("/test", "Bug54947"); + + try { + tomcat.start(); + setPort(tomcat.getConnector().getLocalPort()); + + // Open connection + connect(); + + String[] request = new String[2]; + request[0] = "GET http://localhost:8080/test HTTP/1.1" + CR; + request[1] = LF + + "Connection: close" + CRLF + + CRLF; + + setRequest(request); + processRequest(); // blocks until response has been read + + // Close the connection + disconnect(); + } catch (Exception e) { + return e; + } + return null; + } + + @Override + public boolean isResponseBodyOK() { + if (getResponseBody() == null) { + return false; + } + if (!getResponseBody().contains("OK")) { + return false; + } + return true; + } + + } } Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1486877&r1=1486876&r2=1486877&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue May 28 11:32:00 2013 @@ -109,6 +109,15 @@ </fix> </changelog> </subsection> + <subsection name="Coyote"> + <changelog> + <fix> + <bug>54947</bug>: Fix the HTTP NIO connector that incorrectly rejected a + request if the CRLF terminating the request line was split across + multiple packets. Patch by Konstantin PreiÃer. (markt) + </fix> + </changelog> + </subsection> <subsection name="Jasper"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org