summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-08-27 21:24:34 +0200
committerStef Walter <stef@thewalter.net>2013-08-28 21:51:05 +0200
commit619e81b5ffe0677d1d511ef60b8451434c2a32a0 (patch)
treeb26071e2be6be8cd897c853676a7004c8da9ae9f
parent8a9a90e197d67c58898e959358b9a13482732d3d (diff)
trust: Correctly rewrite other objects in a modifiable persist file
There was a bug where we were rewriting the modified object multiple times.
-rw-r--r--trust/tests/test-token.c74
-rw-r--r--trust/token.c2
2 files changed, 75 insertions, 1 deletions
diff --git a/trust/tests/test-token.c b/trust/tests/test-token.c
index a028d9c..855b56b 100644
--- a/trust/tests/test-token.c
+++ b/trust/tests/test-token.c
@@ -585,6 +585,79 @@ test_write_no_label (void)
test_check_attrs (expected, parsed->elem[0]);
}
+static void
+test_modify_multiple (void)
+{
+ const char *test_data =
+ "[p11-kit-object-v1]\n"
+ "class: data\n"
+ "label: \"first\"\n"
+ "value: \"1\"\n"
+ "\n"
+ "[p11-kit-object-v1]\n"
+ "class: data\n"
+ "label: \"second\"\n"
+ "value: \"2\"\n"
+ "\n"
+ "[p11-kit-object-v1]\n"
+ "class: data\n"
+ "label: \"third\"\n"
+ "value: \"3\"\n";
+
+ CK_ATTRIBUTE first[] = {
+ { CKA_CLASS, &data, sizeof (data) },
+ { CKA_LABEL, "first", 5 },
+ { CKA_VALUE, "1", 1 },
+ { CKA_INVALID },
+ };
+
+ CK_ATTRIBUTE second[] = {
+ { CKA_CLASS, &data, sizeof (data) },
+ { CKA_LABEL, "zwei", 4 },
+ { CKA_VALUE, "2", 2 },
+ { CKA_INVALID },
+ };
+
+ CK_ATTRIBUTE third[] = {
+ { CKA_CLASS, &data, sizeof (data) },
+ { CKA_LABEL, "third", 5 },
+ { CKA_VALUE, "3", 1 },
+ { CKA_INVALID },
+ };
+
+ CK_ATTRIBUTE match = { CKA_LABEL, "second", 6 };
+
+ CK_OBJECT_HANDLE handle;
+ p11_array *parsed;
+ char *path;
+ int ret;
+ CK_RV rv;
+
+ test_write_file (test.directory, "Test.p11-kit", test_data, strlen (test_data));
+
+ /* Reload now that we have this new file */
+ p11_token_load (test.token);
+
+ handle = p11_index_find (test.index, &match, 1);
+
+ rv = p11_index_update (test.index, handle, p11_attrs_dup (second));
+ assert_num_eq (rv, CKR_OK);
+
+ /* Now read in the file and make sure it has all the objects */
+ path = p11_path_build (test.directory, "Test.p11-kit", NULL);
+ ret = p11_parse_file (test.parser, path, NULL, 0);
+ assert_num_eq (ret, P11_PARSE_SUCCESS);
+ free (path);
+
+ parsed = p11_parser_parsed (test.parser);
+ assert_num_eq (parsed->num, 3);
+
+ /* The modified one will be first */
+ test_check_attrs (second, parsed->elem[0]);
+ test_check_attrs (first, parsed->elem[1]);
+ test_check_attrs (third, parsed->elem[2]);
+}
+
int
main (int argc,
char *argv[])
@@ -611,6 +684,7 @@ main (int argc,
p11_test (test_reload_no_origin, "/token/reload-no-origin");
p11_test (test_write_new, "/token/write-new");
p11_test (test_write_no_label, "/token/write-no-label");
+ p11_test (test_modify_multiple, "/token/modify-multiple");
return p11_test_run (argc, argv);
}
diff --git a/trust/token.c b/trust/token.c
index 22363f8..8670ff4 100644
--- a/trust/token.c
+++ b/trust/token.c
@@ -673,7 +673,7 @@ on_index_store (void *data,
for (i = 0; rv == CKR_OK && other && other[i] != 0; i++) {
if (other[i] != handle) {
- object = p11_index_lookup (index, handle);
+ object = p11_index_lookup (index, other[i]);
if (object != NULL)
rv = writer_put_object (file, persist, &buffer, object);
}