[tomcat] branch 8.5.x updated: Avoid NPEs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[tomcat] branch 8.5.x updated: Avoid NPEs

markt
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 5c46969  Avoid NPEs
5c46969 is described below

commit 5c46969e35d9214218a7942de30a939711b037eb
Author: Mark Thomas <[hidden email]>
AuthorDate: Wed Apr 7 16:06:18 2021 +0100

    Avoid NPEs
---
 java/org/apache/coyote/http2/Stream.java | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java
index f3bfee8..f4e2b0f 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -1090,8 +1090,19 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter {
 
             int written = -1;
 
+            // It is still possible that the stream has been closed and inBuffer
+            // set to null between the call to ensureBuffersExist() above and
+            // the sync below. The checks just before and just inside the sync
+            // ensure we don't get any NPEs reported.
+            ByteBuffer tmpInBuffer = inBuffer;
+            if (tmpInBuffer == null) {
+                return -1;
+            }
             // Ensure that only one thread accesses inBuffer at a time
-            synchronized (inBuffer) {
+            synchronized (tmpInBuffer) {
+                if (inBuffer == null) {
+                    return -1;
+                }
                 boolean canRead = false;
                 while (inBuffer.position() == 0 && (canRead = isActive() && !isInputFinished())) {
                     // Need to block until some data is written

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]