You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/08/08 15:29:32 UTC
[tomcat] branch 8.5.x updated: Fix another edge case spotted by Han Li
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new 346312afdb Fix another edge case spotted by Han Li
346312afdb is described below
commit 346312afdb176c75b3328926d4f92d817183699b
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 f8b6d9db84..f426d31672 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -458,7 +458,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 779d308cd0..9dd15841f9 100644
--- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
+++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
@@ -344,40 +344,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org