diff options
author | Stef Walter <stefw@gnome.org> | 2013-06-05 10:03:41 +0200 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-06-05 13:18:52 +0200 |
commit | 1b61494bb10866841e52956a2b65b75259f64e3c (patch) | |
tree | c7aee0bbb0657f3a31011efd67e5f8507e9c1e1d /trust | |
parent | 3dc38f294af5bbe1939d38ec9b3fcd699f97c8ce (diff) |
trust: Fix crash when C_Initialize args are NULL
https://bugs.freedesktop.org/show_bug.cgi?id=65401
Diffstat (limited to 'trust')
-rw-r--r-- | trust/module.c | 5 | ||||
-rw-r--r-- | trust/tests/test-module.c | 18 |
2 files changed, 22 insertions, 1 deletions
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 @@ -144,6 +144,23 @@ test_get_slot_list (CuTest *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) { static CK_C_INITIALIZE_ARGS args = @@ -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); |