summaryrefslogtreecommitdiff
path: root/trust
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-07-08 19:01:24 +0200
committerStef Walter <stef@thewalter.net>2013-07-08 20:35:04 +0200
commita314ab2aa9dbfcbc8d2d9a84554265e498520a20 (patch)
treecfcb4c5ffebfe1c462e9c7c9a4e6e563a81cb6ef /trust
parent3c36c7a68dfefdf75f7239dd7e006e7eb1366620 (diff)
trust: Fix bug with load validation failures
Diffstat (limited to 'trust')
-rw-r--r--trust/index.c5
-rw-r--r--trust/tests/test-index.c50
2 files changed, 53 insertions, 2 deletions
diff --git a/trust/index.c b/trust/index.c
index b84142f..5707714 100644
--- a/trust/index.c
+++ b/trust/index.c
@@ -645,10 +645,11 @@ index_replacev (p11_index *index,
for (j = 0; j < replacen; j++) {
if (!replace[j])
continue;
- rv = p11_index_take (index, replace[j], NULL);
+ attrs = replace[j];
+ replace[j] = NULL;
+ rv = p11_index_take (index, attrs, NULL);
if (rv != CKR_OK)
return rv;
- replace[j] = NULL;
}
return CKR_OK;
diff --git a/trust/tests/test-index.c b/trust/tests/test-index.c
index 73fc359..cf856ee 100644
--- a/trust/tests/test-index.c
+++ b/trust/tests/test-index.c
@@ -653,6 +653,54 @@ test_replace_all (void)
assert_num_eq (4, p11_index_size (test.index));
}
+static CK_RV
+on_index_build_fail (void *data,
+ p11_index *index,
+ CK_ATTRIBUTE *attrs,
+ CK_ATTRIBUTE *merge,
+ CK_ATTRIBUTE **populate)
+{
+ CK_ATTRIBUTE *match = data;
+
+ if (p11_attrs_match (merge, match))
+ return CKR_FUNCTION_FAILED;
+
+ return CKR_OK;
+}
+
+static void
+test_replace_all_build_fails (void)
+{
+ CK_ATTRIBUTE replace[] = {
+ { CKA_LABEL, "odd", 3 },
+ { CKA_VALUE, "one", 3 },
+ { CKA_APPLICATION, "test", 4 },
+ { CKA_INVALID }
+ };
+
+ CK_ATTRIBUTE match[] = {
+ { CKA_LABEL, "odd", 3 },
+ { CKA_INVALID }
+ };
+
+ p11_array *array;
+ p11_index *index;
+ CK_RV rv;
+
+ index = p11_index_new (on_index_build_fail, NULL, NULL, &match);
+ assert_ptr_not_null (index);
+
+ array = p11_array_new (p11_attrs_free);
+ if (!p11_array_push (array, p11_attrs_dup (replace)))
+ assert_not_reached ();
+
+ rv = p11_index_replace_all (index, NULL, CKA_INVALID, array);
+ assert_num_eq (rv, CKR_FUNCTION_FAILED);
+
+ p11_array_free (array);
+ p11_index_free (index);
+}
+
static CK_RV
on_build_populate (void *data,
@@ -1004,5 +1052,7 @@ main (int argc,
p11_test (test_change_called, "/index/change_called");
p11_test (test_change_batch, "/index/change_batch");
p11_test (test_change_nested, "/index/change_nested");
+ p11_test (test_replace_all_build_fails, "/index/replace-all-build-fails");
+
return p11_test_run (argc, argv);
}