summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-12-05 17:49:21 +0000
committerStef Walter <stef@memberwebs.com>2008-12-05 17:49:21 +0000
commit48dc91d0a37f5b45559d017ef224ffcd24c65643 (patch)
tree0c16dd363f72b479672a1b81492b9c6c59695638 /src
parent9d75f49f5818d4cf0f960f2fa113aaefff543df7 (diff)
Fix problems retrieving objects from FindObjects.
Diffstat (limited to 'src')
-rw-r--r--src/object.c53
1 files changed, 20 insertions, 33 deletions
diff --git a/src/object.c b/src/object.c
index 71e6a0d..adfd86e 100644
--- a/src/object.c
+++ b/src/object.c
@@ -40,7 +40,7 @@ destroy_object(CK_SESSION_HANDLE session_rw, CK_SESSION_HANDLE session_ro)
static void
find_objects(CK_SESSION_HANDLE session)
{
- CK_OBJECT_HANDLE_PTR objects;
+ CK_OBJECT_HANDLE objects[1024];
CK_OBJECT_HANDLE extra;
CK_ATTRIBUTE dummy;
CK_ULONG object_count, count;
@@ -85,33 +85,20 @@ find_objects(CK_SESSION_HANDLE session)
rv = (p11t_module_funcs->C_FindObjects)(session, NULL, 0, NULL);
p11t_check_returns("C_FindObjects: invalid session", rv, CKR_ARGUMENTS_BAD);
- /** - Retrieve count of objects, using NULL buffer */
- rv = (p11t_module_funcs->C_FindObjects)(session, NULL, 0, &object_count);
- p11t_check_returns("C_FindObjects: retrieve count", rv, CKR_OK);
+ /** - Retrieve a single object before remainder */
+ rv = (p11t_module_funcs->C_FindObjects)(session, objects, 1, &count);
+ p11t_check_returns("C_FindObjects: single object", rv, CKR_OK);
+ if(count != 0)
+ p11t_check_ulong("C_FindObjects: should return one object", count, 1);
}
- /** - Retrieve count of objects */
- rv = (p11t_module_funcs->C_FindObjects)(session, &extra, 0, &object_count);
- p11t_check_returns("C_FindObjects: retrieve count", rv, CKR_OK);
-
- if(object_count > 0)
+ do
{
- if(p11t_test_unexpected)
- {
- /** - Retrieve a single object before remainder */
- rv = (p11t_module_funcs->C_FindObjects)(session, &extra, 1, &count);
- p11t_check_returns("C_FindObjects: single object", rv, CKR_OK);
- p11t_check_ulong("C_FindObjects: should return one object", count, 1);
- --object_count;
- }
-
/** - Retrieve remaining objects */
- objects = calloc(object_count, sizeof(CK_OBJECT_HANDLE));
- assert(objects);
- rv = (p11t_module_funcs->C_FindObjects)(session, objects, object_count, &count);
+ rv = (p11t_module_funcs->C_FindObjects)(session, objects, 1024, &count);
p11t_check_returns("C_FindObjects: all objects", rv, CKR_OK);
- p11t_check_ulong("C_FindObjects: should return one object", count, object_count);
}
+ while(count == 1024);
if(p11t_test_unexpected)
{
@@ -152,7 +139,7 @@ static void
test_get_attribute_value(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object)
{
CK_OBJECT_CLASS klass;
- CK_ATTRIBUTE attrs[4];
+ CK_ATTRIBUTE attrs[5];
CK_BYTE buffer[8];
CK_BBOOL bools[3];
CK_RV rv;
@@ -349,6 +336,9 @@ p11t_object_tests(void)
if(!p11t_session_login(session_ro))
continue;
+ find_objects(session_ro);
+ test_objects(session_ro);
+
if(session_rw != CK_INVALID)
{
find_objects(session_rw);
@@ -371,7 +361,6 @@ p11t_object_find(CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR attrs,
CK_ULONG n_attrs, CK_ULONG_PTR n_objects)
{
CK_OBJECT_HANDLE_PTR objects;
- CK_OBJECT_HANDLE dummy_obj;
CK_ATTRIBUTE dummy_attr;
CK_ULONG count;
@@ -383,22 +372,20 @@ p11t_object_find(CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR attrs,
if((p11t_module_funcs->C_FindObjectsInit)(session, attrs, n_attrs) != CKR_OK)
return NULL;
- if((p11t_module_funcs->C_FindObjects)(session, &dummy_obj, 0, &count) != CKR_OK)
- return NULL;
-
- if(!count)
+ objects = calloc(1024, sizeof(CK_OBJECT_HANDLE));
+ if((p11t_module_funcs->C_FindObjects)(session, objects, 1024, n_objects) != CKR_OK)
+ {
+ free(objects);
return NULL;
+ }
- objects = calloc(count, sizeof(CK_OBJECT_HANDLE));
- assert(objects);
-
- if((p11t_module_funcs->C_FindObjects)(session, objects, count, n_objects) != CKR_OK)
+ if((p11t_module_funcs->C_FindObjectsFinal)(session) != CKR_OK)
{
free(objects);
return NULL;
}
- if((p11t_module_funcs->C_FindObjectsFinal)(session) != CKR_OK)
+ if(!count)
{
free(objects);
return NULL;