From 3dc38f294af5bbe1939d38ec9b3fcd699f97c8ce Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 5 Jun 2013 10:41:19 +0200 Subject: trust: Fix reinitialization of trust module Track number of C_Initialize calls, and require similar number of C_Finalize calls to finalize. This fixes leaks/disappearing sessions in the trust module. https://bugs.freedesktop.org/show_bug.cgi?id=65401 --- trust/tests/test-module.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'trust/tests/test-module.c') diff --git a/trust/tests/test-module.c b/trust/tests/test-module.c index 16d8037..7f0b1a5 100644 --- a/trust/tests/test-module.c +++ b/trust/tests/test-module.c @@ -144,6 +144,54 @@ test_get_slot_list (CuTest *cu) } static void +test_multi_initialize (CuTest *cu) +{ + static CK_C_INITIALIZE_ARGS args = + { NULL, NULL, NULL, NULL, CKF_OS_LOCKING_OK, NULL, }; + CK_FUNCTION_LIST *module; + CK_SESSION_HANDLE session; + CK_SLOT_ID slots[8]; + CK_SESSION_INFO info; + CK_ULONG count; + 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 (&args); + CuAssertTrue (cu, rv == CKR_OK); + + count = 8; + rv = module->C_GetSlotList (CK_TRUE, slots, &count); + CuAssertTrue (cu, rv == CKR_OK); + CuAssertTrue (cu, count > 0); + + rv = module->C_OpenSession (slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); + CuAssertTrue (cu, rv == CKR_OK); + + rv = module->C_GetSessionInfo (session, &info); + CuAssertTrue (cu, rv == CKR_OK); + CuAssertTrue (cu, info.slotID == slots[0]); + + rv = module->C_Initialize (&args); + CuAssertTrue (cu, rv == CKR_OK); + + rv = module->C_GetSessionInfo (session, &info); + CuAssertTrue (cu, rv == CKR_OK); + CuAssertTrue (cu, info.slotID == slots[0]); + + rv = module->C_Finalize (NULL); + CuAssertIntEquals (cu, CKR_OK, rv); + + rv = module->C_Finalize (NULL); + CuAssertIntEquals (cu, CKR_OK, rv); + + rv = module->C_Finalize (NULL); + CuAssertIntEquals (cu, CKR_CRYPTOKI_NOT_INITIALIZED, rv); +} + +static void test_get_slot_info (CuTest *cu) { CK_SLOT_ID slots[NUM_SLOTS]; @@ -1009,6 +1057,7 @@ main (void) putenv ("P11_KIT_STRICT=1"); p11_library_init (); + SUITE_ADD_TEST (suite, test_multi_initialize); SUITE_ADD_TEST (suite, test_get_slot_list); SUITE_ADD_TEST (suite, test_get_slot_info); SUITE_ADD_TEST (suite, test_get_token_info); -- cgit v1.1 From 1b61494bb10866841e52956a2b65b75259f64e3c Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 5 Jun 2013 10:03:41 +0200 Subject: trust: Fix crash when C_Initialize args are NULL https://bugs.freedesktop.org/show_bug.cgi?id=65401 --- trust/tests/test-module.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'trust/tests/test-module.c') 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); -- cgit v1.1