]> granicus.if.org Git - p11-kit/commitdiff
trust: Fix crash when C_Initialize args are NULL
authorStef Walter <stefw@gnome.org>
Wed, 5 Jun 2013 08:03:41 +0000 (10:03 +0200)
committerStef Walter <stefw@gnome.org>
Wed, 5 Jun 2013 11:18:52 +0000 (13:18 +0200)
https://bugs.freedesktop.org/show_bug.cgi?id=65401

trust/module.c
trust/tests/test-module.c

index 15a4890db188b01afbd31a976cde590c6acdfac7..ba41884761a8fb9f4f5f96bc7d47ceab4feaba96 100644 (file)
@@ -389,6 +389,8 @@ sys_C_Finalize (CK_VOID_PTR reserved)
 static CK_RV
 sys_C_Initialize (CK_VOID_PTR init_args)
 {
+       static CK_C_INITIALIZE_ARGS def_args =
+               { NULL, NULL, NULL, NULL, CKF_OS_LOCKING_OK, NULL, };
        CK_C_INITIALIZE_ARGS *args = NULL;
        int supplied_ok;
        CK_RV rv;
@@ -403,8 +405,9 @@ sys_C_Initialize (CK_VOID_PTR init_args)
 
                rv = CKR_OK;
 
-               /* pReserved must be NULL */
                args = init_args;
+               if (args == NULL)
+                       args = &def_args;
 
                /* ALL supplied function pointers need to have the value either NULL or non-NULL. */
                supplied_ok = (args->CreateMutex == NULL && args->DestroyMutex == NULL &&
index 7f0b1a5db0214f3941fc846e8d915f1792756099..472263aec0a9f02cc3fbaff3ba538e3d6abd60f4 100644 (file)
@@ -143,6 +143,23 @@ test_get_slot_list (CuTest *cu)
        teardown (cu);
 }
 
+static void
+test_null_initialize (CuTest *cu)
+{
+       CK_FUNCTION_LIST *module;
+       CK_RV rv;
+
+       /* This is the entry point of the trust module, linked to this test */
+       rv = C_GetFunctionList (&module);
+       CuAssertTrue (cu, rv == CKR_OK);
+
+       rv = module->C_Initialize (NULL);
+       CuAssertTrue (cu, rv == CKR_OK);
+
+       rv = module->C_Finalize (NULL);
+       CuAssertIntEquals (cu, CKR_OK, rv);
+}
+
 static void
 test_multi_initialize (CuTest *cu)
 {
@@ -1057,6 +1074,7 @@ main (void)
        putenv ("P11_KIT_STRICT=1");
        p11_library_init ();
 
+       SUITE_ADD_TEST (suite, test_null_initialize);
        SUITE_ADD_TEST (suite, test_multi_initialize);
        SUITE_ADD_TEST (suite, test_get_slot_list);
        SUITE_ADD_TEST (suite, test_get_slot_info);