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

commit 319f9a78d8b363195cfc95c3e762eb62a5bb147c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Mar 12 12:10:58 2021 +0000

    Avoid multiple attempts to recycle an HTTP/2 stream triggering an NPE
---
 java/org/apache/coyote/http2/Http2UpgradeHandler.java | 10 ++++++++--
 webapps/docs/changelog.xml                            |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java 
b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
index 8ec1a1b..e494769 100644
--- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
@@ -1869,8 +1869,14 @@ class Http2UpgradeHandler extends AbstractStream 
implements InternalHttpUpgradeH
 
     void replaceStream(AbstractNonZeroStream original, AbstractNonZeroStream 
replacement) {
         synchronized (priorityTreeLock) {
-            streams.replace(original.getIdentifier(), replacement);
-            original.replaceStream(replacement);
+            AbstractNonZeroStream current = 
streams.get(original.getIdentifier());
+            // Might already have been recycled or removed from the priority
+            // tree entirely. Only replace it if the full stream is still in 
the
+            // priority tree.
+            if (current instanceof Stream) {
+                streams.put(original.getIdentifier(), replacement);
+                original.replaceStream(replacement);
+            }
         }
     }
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 8cd6be7..69ccd4b 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -114,6 +114,11 @@
         Re-factor the HTTP/2 implementation classes to better align with 9.0.x
         and 10.0.x to make maintenance simpler. (markt)
       </scode>
+      <fix>
+        Ensure that HTTP/2 streams are only recycled once as multiple attempts
+        to recycle an HTTP/2 stream may result in
+        <code>NullPointerException</code>s. (markt)
+      </fix>
     </changelog>
   </subsection>
 </section>


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

Reply via email to