Bug 1381784, Avoid deadlock in nssSlot_IsTokenPresent, r=ttaubert
authorDaiki Ueno <dueno@redhat.com>
Tue, 18 Jul 2017 11:33:50 +0200
changeset 13466 58026f3ade789361a929b46fd0ba485c86d7bf2c
parent 13458 4c1358d767de5da9a5f34afc2821b281fb37ca57
child 13467 f212be04f3d0265340bf5ae20ffbbccdda68b0aa
push id2275
push userkaie@kuix.de
push dateTue, 18 Jul 2017 19:38:21 +0000
reviewersttaubert
bugs1381784
Bug 1381784, Avoid deadlock in nssSlot_IsTokenPresent, r=ttaubert
lib/dev/devslot.c
--- a/lib/dev/devslot.c
+++ b/lib/dev/devslot.c
@@ -221,25 +221,26 @@ nssSlot_GetCryptokiEPV(
     return slot->epv;
 }
 
 NSS_IMPLEMENT NSSToken *
 nssSlot_GetToken(
     NSSSlot *slot)
 {
     NSSToken *rvToken = NULL;
-    nssSlot_EnterMonitor(slot);
 
-    /* Even if a token should be present, check `slot->token` too as it
-     * might be gone already. This would happen mostly on shutdown. */
-    if (nssSlot_IsTokenPresent(slot) && slot->token) {
-        rvToken = nssToken_AddRef(slot->token);
+    if (nssSlot_IsTokenPresent(slot)) {
+        /* Even if a token should be present, check `slot->token` too as it
+	 * might be gone already. This would happen mostly on shutdown. */
+        nssSlot_EnterMonitor(slot);
+        if (slot->token)
+            rvToken = nssToken_AddRef(slot->token);
+        nssSlot_ExitMonitor(slot);
     }
 
-    nssSlot_ExitMonitor(slot);
     return rvToken;
 }
 
 NSS_IMPLEMENT PRStatus
 nssSession_EnterMonitor(
     nssSession *s)
 {
     if (s->lock)