From: Stef Walter Date: Wed, 5 Jun 2013 08:03:41 +0000 (+0200) Subject: trust: Fix crash when C_Initialize args are NULL X-Git-Tag: 0.18.3~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b61494bb10866841e52956a2b65b75259f64e3c;p=p11-kit trust: Fix crash when C_Initialize args are NULL https://bugs.freedesktop.org/show_bug.cgi?id=65401 --- diff --git a/trust/module.c b/trust/module.c index 15a4890..ba41884 100644 --- a/trust/module.c +++ b/trust/module.c @@ -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 && diff --git a/trust/tests/test-module.c b/trust/tests/test-module.c index 7f0b1a5..472263a 100644 --- a/trust/tests/test-module.c +++ b/trust/tests/test-module.c @@ -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);