]> granicus.if.org Git - p11-kit/commitdiff
trust: Fix bug with load validation failures
authorStef Walter <stef@thewalter.net>
Mon, 8 Jul 2013 17:01:24 +0000 (19:01 +0200)
committerStef Walter <stef@thewalter.net>
Mon, 8 Jul 2013 18:35:04 +0000 (20:35 +0200)
trust/index.c
trust/tests/test-index.c

index b84142f7762f7f4d127c53ef576ffe0acc5f9ff4..5707714d3778fbbd8dd7aaa415d0991210f71823 100644 (file)
@@ -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;
index 73fc35967e86e159a5d7d93344942e699c8d3010..cf856eeae1b58aef62059c9a13c7c9341eb22fe6 100644 (file)
@@ -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);
 }