diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-10-10 12:08:35 +0200 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-10-10 12:16:03 +0200 |
commit | d5a004ded8a0acdb7aa2100b8e116f19d0d9e402 (patch) | |
tree | e42565fb077515a72a417b06afb5dae5047246cd /p11-kit | |
parent | 591c1c14f2ebbcbc3f621456e31e2af1d26820b8 (diff) |
Don't allow recursive calling of C_Initialize on a given module.
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/modules.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/p11-kit/modules.c b/p11-kit/modules.c index c0a000a..d8b7814 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -109,6 +109,7 @@ typedef struct _Module { /* Initialized modules */ CK_C_INITIALIZE_ARGS init_args; int initialize_count; + int initializing; } Module; /* @@ -509,9 +510,13 @@ static CK_RV initialize_module_unlocked_reentrant (Module *mod) { CK_RV rv = CKR_OK; - assert (mod); + if (mod->initializing) { + _p11_message ("p11-kit initialization called recursively"); + return CKR_FUNCTION_FAILED; + } + /* * Increase ref first, so module doesn't get freed out from * underneath us when the mutex is unlocked below. @@ -520,6 +525,7 @@ initialize_module_unlocked_reentrant (Module *mod) if (!mod->initialize_count) { + mod->initializing = 1; debug ("C_Initialize: calling"); _p11_unlock (); @@ -530,6 +536,7 @@ initialize_module_unlocked_reentrant (Module *mod) _p11_lock (); debug ("C_Initialize: result: %lu", rv); + mod->initializing = 0; /* * Because we have the mutex unlocked above, two initializes could |