diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-08-14 18:46:50 +0200 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-08-14 18:49:55 +0200 |
commit | d4abb441450deceff760086dcdf9d493b258074a (patch) | |
tree | f991ceb0d049433d9c1a06b090040d35aeb5fd4a /p11-kit | |
parent | 43169c520292397439bd70fb74e9505d371f7c72 (diff) |
Fix endless loop if module forks during initialization.
* If a module forks during its C_Initialize, previously our
fork handler would try to initialize it again, ad nauseum.
Reported by Nikos on the mailing list.
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/modules.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/p11-kit/modules.c b/p11-kit/modules.c index 693d342..d5dae32 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -446,7 +446,7 @@ initialize_module_unlocked_reentrant (Module *mod) assert (mod); /* - * Initialize first, so module doesn't get freed out from + * Increase ref first, so module doesn't get freed out from * underneath us when the mutex is unlocked below. */ ++mod->ref_count; @@ -499,10 +499,12 @@ reinitialize_after_fork (void) if (gl.modules) { hash_iterate (gl.modules, &iter); while (hash_next (&iter, NULL, (void **)&mod)) { - mod->initialize_count = 0; + if (mod->initialize_count > 0) { + mod->initialize_count = 0; - /* WARNING: Reentrancy can occur here */ - initialize_module_unlocked_reentrant (mod); + /* WARNING: Reentrancy can occur here */ + initialize_module_unlocked_reentrant (mod); + } } } @@ -953,8 +955,8 @@ p11_kit_registered_option (CK_FUNCTION_LIST_PTR module, const char *field) CK_RV p11_kit_initialize_module (CK_FUNCTION_LIST_PTR module) { - Module *mod; Module *allocated = NULL; + Module *mod; CK_RV rv = CKR_OK; /* WARNING: This function must be reentrant for the same arguments */ |