From d5a004ded8a0acdb7aa2100b8e116f19d0d9e402 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 10 Oct 2011 12:08:35 +0200 Subject: Don't allow recursive calling of C_Initialize on a given module. --- p11-kit/modules.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'p11-kit') 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 -- cgit v1.1