diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java index 968a9666c56..fd5e63e0880 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java @@ -898,6 +898,8 @@ public class HttpParser break; } } + else if (ch<=HttpTokens.SPACE) + throw new BadMessage(); else { if (buffer.hasRemaining()) @@ -962,6 +964,8 @@ public class HttpParser break; case HEADER_NAME: + if (ch<0) + throw new BadMessage(); switch(ch) { case HttpTokens.LINE_FEED: @@ -971,7 +975,6 @@ public class HttpParser _header=HttpHeader.CACHE.get(_headerString); } setState(State.HEADER); - break; case HttpTokens.COLON: @@ -982,10 +985,11 @@ public class HttpParser } setState(State.HEADER_VALUE); break; + case HttpTokens.SPACE: case HttpTokens.TAB: - _string.append((char)ch); break; + default: { _string.append((char)ch); @@ -997,6 +1001,12 @@ public class HttpParser break; case HEADER_IN_NAME: + if (ch handler = new Handler(); + HttpParser parser= new HttpParser(handler); + parseAll(parser,buffer); + + assertEquals("GET", _methodOrVersion); + assertEquals("/foo/\u0690/", _uriOrStatus); + assertEquals("HTTP/1.0", _versionOrReason); + assertEquals("Header1", _hdr[0]); + assertEquals("\u00e6 \u00e6", _val[0]); + assertEquals(0, _h); + assertEquals(null,_bad); + } + + + + @Test + public void testBadMethodEncoding() throws Exception + { + ByteBuffer buffer= BufferUtil.toBuffer( + "G\u00e6T / HTTP/1.0\r\nHeader0: value0\r\n\n\n"); + + HttpParser.RequestHandler handler = new Handler(); + HttpParser parser= new HttpParser(handler); + parseAll(parser,buffer); + assertThat(_bad,Matchers.notNullValue()); + } + + @Test + public void testBadVersionEncoding() throws Exception + { + ByteBuffer buffer= BufferUtil.toBuffer( + "GET / H\u00e6P/1.0\r\nHeader0: value0\r\n\n\n"); + + HttpParser.RequestHandler handler = new Handler(); + HttpParser parser= new HttpParser(handler); + parseAll(parser,buffer); + assertThat(_bad,Matchers.notNullValue()); + } + + + @Test + public void testBadHeaderEncoding() throws Exception + { + ByteBuffer buffer= BufferUtil.toBuffer( + "GET / HTTP/1.0\r\nH\u00e6der0: value0\r\n\n\n"); + + HttpParser.RequestHandler handler = new Handler(); + HttpParser parser= new HttpParser(handler); + parseAll(parser,buffer); + assertThat(_bad,Matchers.notNullValue()); + } + @Test public void testSplitHeaderParse() throws Exception {