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 14:03:31 UTC

[tomcat] branch 10.0.x updated: Correct logic of check- thanks to Han Li

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 77683f2e47 Correct logic of check- thanks to Han Li
77683f2e47 is described below

commit 77683f2e4778b84dbaf08f51bb6d4a6c6e63f2a4
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Aug 8 15:03:09 2022 +0100

    Correct logic of check- thanks to Han Li
---
 java/org/apache/coyote/http2/Stream.java           |  2 +-
 .../apache/coyote/http2/TestHttp2Section_8_1.java  | 50 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java
index 13cc3a36f1..0deb2d7237 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()) ||
                 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 3b47dc13ae..eeab280c6b 100644
--- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
+++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
@@ -319,6 +319,31 @@ public class TestHttp2Section_8_1 extends Http2TestBase {
     }
 
 
+    @Test
+    public void testHostHeaderConsistentNoPort() 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"));
+        headers.add(new Header(":path", "/simple"));
+        headers.add(new Header("host", "localhost"));
+
+        byte[] headersFrameHeader = new byte[9];
+        ByteBuffer headersPayload = ByteBuffer.allocate(128);
+
+        buildGetRequest(headersFrameHeader, headersPayload, null, headers , 3);
+
+        writeFrame(headersFrameHeader, headersPayload);
+
+        parser.readFrame(true);
+
+        String trace = output.getTrace();
+        Assert.assertTrue(trace, trace.contains("3-Header-[:status]-[200]"));
+    }
+
+
     @Test
     public void testHostHeaderInconsistent() throws Exception {
         http2Connect();
@@ -344,6 +369,31 @@ public class TestHttp2Section_8_1 extends Http2TestBase {
     }
 
 
+    @Test
+    public void testHostHeaderInconsistentNoPort() 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"));
+        headers.add(new Header(":path", "/simple"));
+        headers.add(new Header("host", "otherhost"));
+
+        byte[] headersFrameHeader = new byte[9];
+        ByteBuffer headersPayload = ByteBuffer.allocate(128);
+
+        buildGetRequest(headersFrameHeader, headersPayload, null, headers , 3);
+
+        writeFrame(headersFrameHeader, headersPayload);
+
+        parser.readFrame(true);
+
+        String trace = output.getTrace();
+        Assert.assertTrue(trace, trace.contains("0-Goaway-[1]-[9]"));
+    }
+
+
     private void doInvalidPseudoHeaderTest(List<Header> headers) throws Exception {
         http2Connect();
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org