Blame SOURCES/0006-Fix-SSLSocket-closure.patch

fe62e3
From 278ff534e0a30cb112e8c29de573bf45b4264ad2 Mon Sep 17 00:00:00 2001
fe62e3
From: Alexander Scheel <ascheel@redhat.com>
fe62e3
Date: Wed, 15 Apr 2020 08:20:37 -0400
fe62e3
Subject: [PATCH] Fix SSLSocket closure
fe62e3
fe62e3
Signed-off-by: Alexander Scheel <ascheel@redhat.com>
fe62e3
---
fe62e3
 org/mozilla/jss/ssl/SocketBase.java | 14 +++++++++++-
fe62e3
 org/mozilla/jss/ssl/common.c        | 34 +++++++++++++++++++----------
fe62e3
 2 files changed, 36 insertions(+), 12 deletions(-)
fe62e3
fe62e3
diff --git a/org/mozilla/jss/ssl/SocketBase.java b/org/mozilla/jss/ssl/SocketBase.java
fe62e3
index 2c835913..27109369 100644
fe62e3
--- a/org/mozilla/jss/ssl/SocketBase.java
fe62e3
+++ b/org/mozilla/jss/ssl/SocketBase.java
fe62e3
@@ -106,7 +106,19 @@ class SocketBase {
fe62e3
     static final int SSL_AF_INET6 = 51;
fe62e3
 
fe62e3
     void close() throws IOException {
fe62e3
-        socketClose();
fe62e3
+        try {
fe62e3
+            if (sockProxy != null) {
fe62e3
+                socketClose();
fe62e3
+                sockProxy.close();
fe62e3
+            }
fe62e3
+        } catch (Exception e) {
fe62e3
+            String msg = "Unexpected exception while trying to finalize ";
fe62e3
+            msg += "SocketProxy: " + e.getMessage();
fe62e3
+
fe62e3
+            throw new IOException(msg, e);
fe62e3
+        } finally {
fe62e3
+            sockProxy = null;
fe62e3
+        }
fe62e3
     }
fe62e3
 
fe62e3
     // SSLServerSocket and SSLSocket close methods
fe62e3
diff --git a/org/mozilla/jss/ssl/common.c b/org/mozilla/jss/ssl/common.c
fe62e3
index 2db9fda1..2c52a9d6 100644
fe62e3
--- a/org/mozilla/jss/ssl/common.c
fe62e3
+++ b/org/mozilla/jss/ssl/common.c
fe62e3
@@ -333,21 +333,28 @@ JNIEXPORT void JNICALL
fe62e3
 Java_org_mozilla_jss_ssl_SocketProxy_releaseNativeResources
fe62e3
     (JNIEnv *env, jobject this)
fe62e3
 {
fe62e3
-    /* SSLSocket.close and SSLServerSocket.close call	  */
fe62e3
-    /* SocketBase.close to destroy all native Resources */
fe62e3
-    /* attached to the socket. There is no native resource */
fe62e3
-    /* to release after close has been called. This method  */
fe62e3
-    /* remains because SocketProxy extends org.mozilla.jss.util.NativeProxy*/
fe62e3
-    /* which defines releaseNativeResources as abstract and */
fe62e3
-    /* therefore must be implemented by SocketProxy */
fe62e3
+    JSSL_SocketData *sockdata;
fe62e3
+
fe62e3
+    PR_ASSERT(env != NULL && this != NULL);
fe62e3
+
fe62e3
+    if (JSS_getPtrFromProxy(env, this, (void**)&sockdata) != PR_SUCCESS) {
fe62e3
+        return;
fe62e3
+    }
fe62e3
+
fe62e3
+    JSSL_DestroySocketData(env, sockdata);
fe62e3
 }
fe62e3
 
fe62e3
 void
fe62e3
 JSSL_DestroySocketData(JNIEnv *env, JSSL_SocketData *sd)
fe62e3
 {
fe62e3
-    PR_ASSERT(sd != NULL);
fe62e3
+    if (sd == NULL) {
fe62e3
+        return;
fe62e3
+    }
fe62e3
 
fe62e3
-    PR_Close(sd->fd);
fe62e3
+    if (sd->fd != NULL) {
fe62e3
+        PR_Close(sd->fd);
fe62e3
+        sd->fd = NULL;
fe62e3
+    }
fe62e3
 
fe62e3
     if( sd->socketObject != NULL ) {
fe62e3
         DELETE_WEAK_GLOBAL_REF(env, sd->socketObject );
fe62e3
@@ -367,6 +374,8 @@ JSSL_DestroySocketData(JNIEnv *env, JSSL_SocketData *sd)
fe62e3
     if( sd->lock != NULL ) {
fe62e3
         PR_DestroyLock(sd->lock);
fe62e3
     }
fe62e3
+
fe62e3
+    memset(sd, 0, sizeof(JSSL_SocketData));
fe62e3
     PR_Free(sd);
fe62e3
 }
fe62e3
 
fe62e3
@@ -540,12 +549,15 @@ Java_org_mozilla_jss_ssl_SocketBase_socketClose(JNIEnv *env, jobject self)
fe62e3
     JSSL_SocketData *sock = NULL;
fe62e3
 
fe62e3
     /* get the FD */
fe62e3
-    if( JSSL_getSockData(env, self, &sock) != PR_SUCCESS) {
fe62e3
+    if( JSSL_getSockData(env, self, &sock) != PR_SUCCESS || sock == NULL) {
fe62e3
         /* exception was thrown */
fe62e3
         return;
fe62e3
     }
fe62e3
 
fe62e3
-    JSSL_DestroySocketData(env, sock);
fe62e3
+    if (sock->fd != NULL) {
fe62e3
+        PR_Close(sock->fd);
fe62e3
+        sock->fd = NULL;
fe62e3
+    }
fe62e3
 }
fe62e3
 
fe62e3
 JNIEXPORT void JNICALL
fe62e3
-- 
fe62e3
2.25.2
fe62e3