You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2020/02/19 15:47:48 UTC

[tomcat] branch 8.5.x updated: Make native pointers fields final

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

remm 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 bbe2494  Make native pointers fields final
bbe2494 is described below

commit bbe24946365042b2c68d8db3169dba7558b5a1e7
Author: remm <re...@apache.org>
AuthorDate: Wed Feb 19 16:42:41 2020 +0100

    Make native pointers fields final
    
    And check them for non null on shutdown.
    Based on code submitted by Manuel Dominguez Sarmiento.
---
 .../apache/tomcat/util/net/openssl/OpenSSLEngine.java    | 16 ++++++++--------
 webapps/docs/changelog.xml                               |  4 ++++
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java b/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java
index ede30a8..04f8558 100644
--- a/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java
+++ b/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java
@@ -133,8 +133,8 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn
     private static final long EMPTY_ADDR = Buffer.address(ByteBuffer.allocate(0));
 
     // OpenSSL state
-    private long ssl;
-    private long networkBIO;
+    private final long ssl;
+    private final long networkBIO;
 
     private enum Accepted { NOT, IMPLICIT, EXPLICIT }
     private Accepted accepted = Accepted.NOT;
@@ -197,10 +197,8 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn
             throw new IllegalArgumentException(sm.getString("engine.noSSLContext"));
         }
         session = new OpenSSLSession();
-        destroyed = true;
         ssl = SSL.newSSL(sslCtx, !clientMode);
         networkBIO = SSL.makeNetworkBIO(ssl);
-        destroyed = false;
         this.fallbackApplicationProtocol = fallbackApplicationProtocol;
         this.clientMode = clientMode;
         this.sessionContext = sessionContext;
@@ -221,10 +219,12 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn
     public synchronized void shutdown() {
         if (!destroyed) {
             destroyed = true;
-            SSL.freeBIO(networkBIO);
-            SSL.freeSSL(ssl);
-            ssl = networkBIO = 0;
-
+            if (networkBIO != 0) {
+                SSL.freeBIO(networkBIO);
+            }
+            if (ssl != 0) {
+                SSL.freeSSL(ssl);
+            }
             // internal errors can cause shutdown without marking the engine closed
             isInboundDone = isOutboundDone = engineClosed = true;
         }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 1692c46..4f60302 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -84,6 +84,10 @@
         <bug>64141</bug>: If using a CA certificate, remove a default value
         for the truststore file when not using a JSSE configuration. (remm)
       </fix>
+      <fix>
+        Improve robustness of OpenSSLEngine shutdown. Based on code submitted
+        by Manuel Dominguez Sarmiento. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


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