Skip to content
Browse files

Check the lib is initialized before logging

C_CloseSession() and C_CloseAllSessions() were calling sc_debug() before
any check on the validity of the context. So if C_Initialize() was not
previously called you get an assert:
log.c:76: sc_do_log_va: Assertion `ctx != ((void *)0)' failed.
  • Loading branch information...
1 parent 40cb1c9 commit ce2d3c09bed53e4a9e77e327d39f0a4e2187ba3a @LudovicRousseau LudovicRousseau committed Jun 21, 2011
Showing with 8 additions and 4 deletions.
  1. +8 −4 src/pkcs11/pkcs11-session.c
View
12 src/pkcs11/pkcs11-session.c
@@ -137,11 +137,14 @@ CK_RV C_CloseSession(CK_SESSION_HANDLE hSession)
{ /* the session's handle */
CK_RV rv;
+ rv = sc_pkcs11_lock();
+ if (rv != CKR_OK)
+ return rv;
+
sc_debug(context, SC_LOG_DEBUG_NORMAL, "C_CloseSession(0x%lx)\n", hSession);
- rv = sc_pkcs11_lock();
- if (rv == CKR_OK)
- rv = sc_pkcs11_close_session(hSession);
+ rv = sc_pkcs11_close_session(hSession);
+
sc_pkcs11_unlock();
return rv;
}
@@ -151,11 +154,12 @@ CK_RV C_CloseAllSessions(CK_SLOT_ID slotID)
CK_RV rv;
struct sc_pkcs11_slot *slot;
- sc_debug(context, SC_LOG_DEBUG_NORMAL, "C_CloseAllSessions(0x%lx)\n", slotID);
rv = sc_pkcs11_lock();
if (rv != CKR_OK)
return rv;
+ sc_debug(context, SC_LOG_DEBUG_NORMAL, "C_CloseAllSessions(0x%lx)\n", slotID);
+
rv = slot_get_token(slotID, &slot);
if (rv != CKR_OK)
goto out;

0 comments on commit ce2d3c0

Please sign in to comment.
Something went wrong with that request. Please try again.