This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.0.x by this push: new 53ba52616d Fix another edge case spotted by Han Li 53ba52616d is described below commit 53ba52616d05df28745d6ece571920face054746 Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Aug 8 16:29:11 2022 +0100 Fix another edge case spotted by Han Li --- java/org/apache/coyote/http2/Stream.java | 2 +- .../apache/coyote/http2/TestHttp2Section_8_1.java | 46 ++++++++++++++-------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java index 0deb2d7237..820091e7f3 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -467,7 +467,7 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter { throw new HpackException(sm.getString("stream.header.invalid", getConnectionId(), getIdAsString(), "host", value)); } - if (i == -1 && !value.equals(coyoteRequest.serverName().getString()) || + if (i == -1 && (!value.equals(coyoteRequest.serverName().getString()) || coyoteRequest.getServerPort() != -1) || i > -1 && ((!value.substring(0, i).equals(coyoteRequest.serverName().getString()) || Integer.parseInt(value.substring(i + 1)) != coyoteRequest.getServerPort()))) { // Host value inconsistent diff --git a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java index eeab280c6b..4dca8550fe 100644 --- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java +++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java @@ -345,40 +345,52 @@ public class TestHttp2Section_8_1 extends Http2TestBase { @Test - public void testHostHeaderInconsistent() throws Exception { + public void testHostHeaderInconsistent01() throws Exception { http2Connect(); - List<Header> headers = new ArrayList<>(4); - headers.add(new Header(":method", "GET")); - headers.add(new Header(":scheme", "http")); - headers.add(new Header(":authority", "localhost:" + getPort())); - headers.add(new Header(":path", "/simple")); - headers.add(new Header("host", "otherhost:" + getPort())); + doTestHostHeaderInconsistent("localhost:" + getPort(), "otherhost:" + getPort()); + } - byte[] headersFrameHeader = new byte[9]; - ByteBuffer headersPayload = ByteBuffer.allocate(128); - buildGetRequest(headersFrameHeader, headersPayload, null, headers , 3); + @Test + public void testHostHeaderInconsistent02() throws Exception { + http2Connect(); - writeFrame(headersFrameHeader, headersPayload); + doTestHostHeaderInconsistent("localhost", "otherhost"); + } - parser.readFrame(true); - String trace = output.getTrace(); - Assert.assertTrue(trace, trace.contains("0-Goaway-[1]-[9]")); + @Test + public void testHostHeaderInconsistent03() throws Exception { + http2Connect(); + + doTestHostHeaderInconsistent("localhost:" + getPort(), "localhost"); + } + + + @Test + public void testHostHeaderInconsistent04() throws Exception { + http2Connect(); + + doTestHostHeaderInconsistent("localhost", "localhost:" + getPort()); } @Test - public void testHostHeaderInconsistentNoPort() throws Exception { + public void testHostHeaderInconsistent05() throws Exception { http2Connect(); + doTestHostHeaderInconsistent("localhost:" + getPort(), "otherhost:" + (getPort() + 1)); + } + + + private void doTestHostHeaderInconsistent(String authority, String host) throws Exception { List<Header> headers = new ArrayList<>(4); headers.add(new Header(":method", "GET")); headers.add(new Header(":scheme", "http")); - headers.add(new Header(":authority", "localhost")); + headers.add(new Header(":authority", authority)); headers.add(new Header(":path", "/simple")); - headers.add(new Header("host", "otherhost")); + headers.add(new Header("host", host)); byte[] headersFrameHeader = new byte[9]; ByteBuffer headersPayload = ByteBuffer.allocate(128); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org