Fix crash in ssl retransmission thread
authorJoonghwan Lee <jh05.lee@samsung.com>
Thu, 19 Jan 2017 08:33:20 +0000 (17:33 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Thu, 9 Feb 2017 06:49:18 +0000 (06:49 +0000)
It is possible to happen segmentation fault if retransmission thread
lock a mutex during CAdeinitSslAdapter function is called

Patch 1: Initial upload

Change-Id: I446aeb2cc9d6cd07d2683984ba2783ab72020c58
Signed-off-by: Joonghwan Lee <jh05.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16575
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17107

resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c

index ec9a423..b6a795e 100644 (file)
@@ -1316,6 +1316,7 @@ static void StopRetransmit()
     if (g_caSslContext)
     {
         unregisterTimer(g_caSslContext->timerId);
+        g_caSslContext->timerId= -1;
     }
 }
 #endif
@@ -1399,12 +1400,15 @@ static int StartRetransmit()
     uint32_t listIndex = 0;
     uint32_t listLength = 0;
     SslEndPoint_t *tep = NULL;
+
+    oc_mutex_lock(g_sslContextMutex);
     if (NULL == g_caSslContext)
     {
         OIC_LOG(ERROR, NET_SSL_TAG, "Context is NULL. Stop retransmission");
+        oc_mutex_unlock(g_sslContextMutex);
         return -1;
     }
-    oc_mutex_lock(g_sslContextMutex);
+
     if (g_caSslContext->timerId != -1)
     {
         //clear previous timer