]> granicus.if.org Git - curl/commitdiff
nss: do not leak PKCS #11 slot while loading a key
authorKamil Dudka <kdudka@redhat.com>
Mon, 24 Apr 2017 13:01:04 +0000 (15:01 +0200)
committerKamil Dudka <kdudka@redhat.com>
Tue, 25 Apr 2017 11:22:33 +0000 (13:22 +0200)
It could prevent nss-pem from being unloaded later on.

Bug: https://bugzilla.redhat.com/1444860

lib/vtls/nss.c

index e1a122947fdbc93a98906d5d5fb5e657cc343473..0e57ab45dccad7202b8ed71de84f71e8876ccd28 100644 (file)
@@ -603,7 +603,7 @@ fail:
 static CURLcode nss_load_key(struct connectdata *conn, int sockindex,
                              char *key_file)
 {
-  PK11SlotInfo *slot;
+  PK11SlotInfo *slot, *tmp;
   SECStatus status;
   CURLcode result;
   struct ssl_connect_data *ssl = conn->ssl;
@@ -622,7 +622,9 @@ static CURLcode nss_load_key(struct connectdata *conn, int sockindex,
     return CURLE_SSL_CERTPROBLEM;
 
   /* This will force the token to be seen as re-inserted */
-  SECMOD_WaitForAnyTokenEvent(mod, 0, 0);
+  tmp = SECMOD_WaitForAnyTokenEvent(mod, 0, 0);
+  if(tmp)
+    PK11_FreeSlot(tmp);
   PK11_IsPresent(slot);
 
   status = PK11_Authenticate(slot, PR_TRUE, SSL_SET_OPTION(key_passwd));