This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 868287c  Avoid potential NPEs introduced in smaller footprint for 
closed streams
868287c is described below

commit 868287cafee0bf89a82370701740a035924ed9a0
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Aug 12 18:12:43 2020 +0100

    Avoid potential NPEs introduced in smaller footprint for closed streams
---
 java/org/apache/coyote/http2/Stream.java | 18 ++++++++++++++++--
 webapps/docs/changelog.xml               |  4 ++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/coyote/http2/Stream.java 
b/java/org/apache/coyote/http2/Stream.java
index fa9394c..4c99103 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -472,8 +472,12 @@ class Stream extends AbstractStream implements 
HeaderEmitter {
             }
 
             if (headerState == HEADER_STATE_TRAILER) {
-                // HTTP/2 headers are already always lower case
-                coyoteRequest.getTrailerFields().put(name, value);
+                // Avoid NPE if Stream has been closed on Stream specific 
thread
+                Request coyoteRequest = this.coyoteRequest;
+                if (coyoteRequest != null) {
+                    // HTTP/2 headers are already always lower case
+                    coyoteRequest.getTrailerFields().put(name, value);
+                }
             } else {
                 coyoteRequest.getMimeHeaders().addValue(name).setString(value);
             }
@@ -585,6 +589,11 @@ class Stream extends AbstractStream implements 
HeaderEmitter {
 
 
     final ByteBuffer getInputByteBuffer() {
+        // Avoid NPE if Stream has been closed on Stream specific thread
+        StreamInputBuffer inputBuffer = this.inputBuffer;
+        if (inputBuffer == null) {
+            return null;
+        }
         return inputBuffer.getInBuffer();
     }
 
@@ -615,6 +624,11 @@ class Stream extends AbstractStream implements 
HeaderEmitter {
 
     final void receivedData(int payloadSize) throws ConnectionException {
         contentLengthReceived += payloadSize;
+        Request coyoteRequest = this.coyoteRequest;
+        // Avoid NPE if Stream has been closed on Stream specific thread
+        if (coyoteRequest == null) {
+            return;
+        }
         long contentLengthHeader = coyoteRequest.getContentLengthLong();
         if (contentLengthHeader > -1 && contentLengthReceived > 
contentLengthHeader) {
             throw new 
ConnectionException(sm.getString("stream.header.contentLength",
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 548456b..7a99c85 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -91,6 +91,10 @@
         <code>ServletInputStream.available()</code> to provide a more accurate
         return value, particularly when end of stream has been reached. (markt)
       </fix>
+      <fix>
+        Avoid several potential NPEs introduced in the changes in the previous
+        release to reduce the memory footprint of closed HTTP/2 streams. 
(markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="WebSocket">


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

Reply via email to