]> granicus.if.org Git - p11-kit/commitdiff
Fix bugs in the p11-kit proxy module.
authorStef Walter <stefw@collabora.co.uk>
Wed, 24 Aug 2011 13:34:13 +0000 (15:34 +0200)
committerStef Walter <stefw@collabora.co.uk>
Wed, 24 Aug 2011 13:34:13 +0000 (15:34 +0200)
 * Initialize the mappings properly
 * Lookup session handles correctly
 * Debug initialization and finalization

p11-kit/debug.c
p11-kit/debug.h
p11-kit/proxy.c

index eb7eef05877262ee02c1303223247a961ec496c6..e4b39f069a119cefeef8bf739349024f536c027c 100644 (file)
@@ -54,6 +54,7 @@ static struct DebugKey debug_keys[] = {
        { "lib", DEBUG_LIB },
        { "conf", DEBUG_CONF },
        { "uri", DEBUG_URI },
+       { "proxy", DEBUG_PROXY },
        { 0, }
 };
 
index acc9ca60d1c6d7444c5aed0f0faca8f8f1127374..2d6a226322340116b016d6820b6e68ca33d8d75a 100644 (file)
@@ -39,7 +39,8 @@
 typedef enum {
        DEBUG_LIB = 1 << 1,
        DEBUG_CONF = 1 << 2,
-       DEBUG_URI = 1 << 3
+       DEBUG_URI = 1 << 3,
+       DEBUG_PROXY = 1 << 4,
 } DebugFlags;
 
 extern int        debug_current_flags;
index c3c7e80a4a27c77c967fae34c790c05cd846eb69..0f0fc42f265d15c58697dec81a30bc3f37ab74d1 100644 (file)
@@ -35,6 +35,8 @@
 
 #include "config.h"
 
+#define DEBUG_FLAG DEBUG_PROXY
+#include "debug.h"
 #include "hashmap.h"
 #include "pkcs11.h"
 #include "p11-kit.h"
@@ -145,7 +147,7 @@ map_session_to_real (CK_SESSION_HANDLE_PTR handle, Mapping *mapping, Session *se
                        rv = CKR_CRYPTOKI_NOT_INITIALIZED;
                } else {
                        assert (gl.sessions);
-                       sess = hash_get (gl.sessions, &handle);
+                       sess = hash_get (gl.sessions, handle);
                        if (sess != NULL) {
                                *handle = sess->real_session;
                                rv = map_slot_unlocked (sess->wrap_slot, mapping);
@@ -202,25 +204,30 @@ proxy_C_Finalize (CK_VOID_PTR reserved)
 {
        CK_RV rv;
 
+       debug ("in");
+
        /* WARNING: This function must be reentrant */
 
-       if (reserved)
-               return CKR_ARGUMENTS_BAD;
+       if (reserved) {
+               rv = CKR_ARGUMENTS_BAD;
 
-       _p11_lock ();
+       } else {
+               _p11_lock ();
 
-               /* WARNING: Reentrancy can occur here */
-               rv = _p11_kit_finalize_registered_unlocked_reentrant ();
+                       /* WARNING: Reentrancy can occur here */
+                       rv = _p11_kit_finalize_registered_unlocked_reentrant ();
 
-               /*
-                * If modules are all gone, then this was the last
-                * finalize, so cleanup our mappings
-                */
-               if (gl.mappings_refs)
-                       finalize_mappings_unlocked ();
+                       /*
+                        * If modules are all gone, then this was the last
+                        * finalize, so cleanup our mappings
+                        */
+                       if (gl.mappings_refs)
+                               finalize_mappings_unlocked ();
 
-       _p11_unlock ();
+               _p11_unlock ();
+       }
 
+       debug ("out: %lu", rv);
        return rv;
 }
 
@@ -288,6 +295,8 @@ initialize_mappings_unlocked_reentrant (void)
        }
 
        assert (!gl.sessions);
+       gl.mappings = mappings;
+       gl.n_mappings = n_mappings;
        gl.sessions = hash_create (hash_ulongptr_hash, hash_ulongptr_equal, NULL, free);
        ++gl.mappings_refs;
 
@@ -302,20 +311,25 @@ proxy_C_Initialize (CK_VOID_PTR init_args)
 
        /* WARNING: This function must be reentrant */
 
+       debug ("in");
+
        _p11_lock ();
 
                /* WARNING: Reentrancy can occur here */
                rv = _p11_kit_initialize_registered_unlocked_reentrant ();
 
                /* WARNING: Reentrancy can occur here */
-               if (rv == CKR_OK && !gl.mappings_refs == 0)
+               if (rv == CKR_OK && gl.mappings_refs == 0)
                        rv = initialize_mappings_unlocked_reentrant ();
 
        _p11_unlock ();
 
+       debug ("here");
+
        if (rv != CKR_OK)
                proxy_C_Finalize (NULL);
 
+       debug ("out: %lu", rv);
        return rv;
 }