diff options
-rw-r--r-- | common/tests/test-path.c | 90 | ||||
-rw-r--r-- | p11-kit/modules.c | 2 | ||||
-rw-r--r-- | trust/asn1.c | 4 | ||||
-rw-r--r-- | trust/builder.c | 6 | ||||
-rw-r--r-- | trust/extract-openssl.c | 1 | ||||
-rw-r--r-- | trust/index.c | 2 | ||||
-rw-r--r-- | trust/parser.c | 1 | ||||
-rw-r--r-- | trust/tests/Makefile.am | 12 | ||||
-rw-r--r-- | trust/tests/test-asn1.c | 3 | ||||
-rw-r--r-- | trust/tests/test-builder.c | 4 | ||||
-rw-r--r-- | trust/token.c | 10 |
11 files changed, 79 insertions, 56 deletions
diff --git a/common/tests/test-path.c b/common/tests/test-path.c index a6ba54d..57619c8 100644 --- a/common/tests/test-path.c +++ b/common/tests/test-path.c @@ -75,34 +75,40 @@ test_base (void) } } -#define check_equals_and_free(ex, ac) \ - do { assert_str_eq (ex, ac); free (ac); } while (0) +#define assert_str_eq_free(ex, ac) \ + do { const char *__s1 = (ex); \ + char *__s2 = (ac); \ + if (__s1 && __s2 && strcmp (__s1, __s2) == 0) ; else \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s == %s): (%s == %s)", \ + #ex, #ac, __s1 ? __s1 : "(null)", __s2 ? __s2 : "(null)"); \ + free (__s2); \ + } while (0) static void test_build (void) { #ifdef OS_UNIX - check_equals_and_free ("/root/second", - p11_path_build ("/root", "second", NULL)); - check_equals_and_free ("/root/second", - p11_path_build ("/root", "/second", NULL)); - check_equals_and_free ("/root/second", - p11_path_build ("/root/", "second", NULL)); - check_equals_and_free ("/root/second/third", - p11_path_build ("/root", "second", "third", NULL)); - check_equals_and_free ("/root/second/third", - p11_path_build ("/root", "/second/third", NULL)); + assert_str_eq_free ("/root/second", + p11_path_build ("/root", "second", NULL)); + assert_str_eq_free ("/root/second", + p11_path_build ("/root", "/second", NULL)); + assert_str_eq_free ("/root/second", + p11_path_build ("/root/", "second", NULL)); + assert_str_eq_free ("/root/second/third", + p11_path_build ("/root", "second", "third", NULL)); + assert_str_eq_free ("/root/second/third", + p11_path_build ("/root", "/second/third", NULL)); #else /* OS_WIN32 */ - check_equals_and_free ("C:\\root\\second", - p11_path_build ("C:\\root", "second", NULL)); - check_equals_and_free ("C:\\root\\second", - p11_path_build ("C:\\root", "\\second", NULL)); - check_equals_and_free ("C:\\root\\second", - p11_path_build ("C:\\root\\", "second", NULL)); - check_equals_and_free ("C:\\root\\second\\third", - p11_path_build ("C:\\root", "second", "third", NULL)); - check_equals_and_free ("C:\\root\\second/third", - p11_path_build ("C:\\root", "second/third", NULL)); + assert_str_eq_free ("C:\\root\\second", + p11_path_build ("C:\\root", "second", NULL)); + assert_str_eq_free ("C:\\root\\second", + p11_path_build ("C:\\root", "\\second", NULL)); + assert_str_eq_free ("C:\\root\\second", + p11_path_build ("C:\\root\\", "second", NULL)); + assert_str_eq_free ("C:\\root\\second\\third", + p11_path_build ("C:\\root", "second", "third", NULL)); + assert_str_eq_free ("C:\\root\\second/third", + p11_path_build ("C:\\root", "second/third", NULL)); #endif } @@ -113,22 +119,22 @@ test_expand (void) #ifdef OS_UNIX putenv ("HOME=/home/blah"); - check_equals_and_free ("/home/blah/my/path", - p11_path_expand ("~/my/path")); - check_equals_and_free ("/home/blah", - p11_path_expand ("~")); + assert_str_eq_free ("/home/blah/my/path", + p11_path_expand ("~/my/path")); + assert_str_eq_free ("/home/blah", + p11_path_expand ("~")); putenv ("XDG_CONFIG_HOME=/my"); - check_equals_and_free ("/my/path", - p11_path_expand ("~/.config/path")); + assert_str_eq_free ("/my/path", + p11_path_expand ("~/.config/path")); putenv ("XDG_CONFIG_HOME="); - check_equals_and_free ("/home/blah/.config/path", - p11_path_expand ("~/.config/path")); + assert_str_eq_free ("/home/blah/.config/path", + p11_path_expand ("~/.config/path")); #else /* OS_WIN32 */ putenv ("HOME=C:\\Users\\blah"); - check_equals_and_free ("C:\\Users\\blah\\path", - p11_path_expand ("~/my/path")); - check_equals_and_free ("C:\\Users\\blah\\path", - p11_path_expand ("~\\path")); + assert_str_eq_free ("C:\\Users\\blah\\path", + p11_path_expand ("~/my/path")); + assert_str_eq_free ("C:\\Users\\blah\\path", + p11_path_expand ("~\\path")); #endif putenv("HOME="); @@ -153,14 +159,14 @@ test_absolute (void) static void test_parent (void) { - check_equals_and_free ("/", p11_path_parent ("/root")); - check_equals_and_free ("/", p11_path_parent ("/root/")); - check_equals_and_free ("/", p11_path_parent ("/root//")); - check_equals_and_free ("/root", p11_path_parent ("/root/second")); - check_equals_and_free ("/root", p11_path_parent ("/root//second")); - check_equals_and_free ("/root", p11_path_parent ("/root//second//")); - check_equals_and_free ("/root", p11_path_parent ("/root///second")); - check_equals_and_free ("/root/second", p11_path_parent ("/root/second/test.file")); + assert_str_eq_free ("/", p11_path_parent ("/root")); + assert_str_eq_free ("/", p11_path_parent ("/root/")); + assert_str_eq_free ("/", p11_path_parent ("/root//")); + assert_str_eq_free ("/root", p11_path_parent ("/root/second")); + assert_str_eq_free ("/root", p11_path_parent ("/root//second")); + assert_str_eq_free ("/root", p11_path_parent ("/root//second//")); + assert_str_eq_free ("/root", p11_path_parent ("/root///second")); + assert_str_eq_free ("/root/second", p11_path_parent ("/root/second/test.file")); assert_ptr_eq (NULL, p11_path_parent ("/")); assert_ptr_eq (NULL, p11_path_parent ("//")); assert_ptr_eq (NULL, p11_path_parent ("")); diff --git a/p11-kit/modules.c b/p11-kit/modules.c index 43ace18..b373544 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -467,8 +467,10 @@ take_config_and_load_module_inlock (char **name, return CKR_OK; /* Take ownership of thes evariables */ + p11_dict_free (mod->config); mod->config = *config; *config = NULL; + free (mod->name); mod->name = *name; *name = NULL; mod->critical = critical; diff --git a/trust/asn1.c b/trust/asn1.c index 7ed3b01..dd1812d 100644 --- a/trust/asn1.c +++ b/trust/asn1.c @@ -327,8 +327,10 @@ p11_asn1_cache_take (p11_asn1_cache *cache, { asn1_item *item; - if (cache == NULL) + if (cache == NULL) { + asn1_delete_structure (&node); return; + } return_if_fail (struct_name != NULL); return_if_fail (der != NULL); diff --git a/trust/builder.c b/trust/builder.c index 2daadb3..18c09ad 100644 --- a/trust/builder.c +++ b/trust/builder.c @@ -1018,9 +1018,6 @@ build_for_schema (p11_builder *builder, } } - if (populate && schema->populate) - *extra = schema->populate (builder, index, merge); - /* Validate the result, before committing to the change. */ if (!loading && schema->validate) { rv = (schema->validate) (builder, attrs, merge); @@ -1028,6 +1025,9 @@ build_for_schema (p11_builder *builder, return rv; } + if (populate && schema->populate) + *extra = schema->populate (builder, index, merge); + return CKR_OK; } diff --git a/trust/extract-openssl.c b/trust/extract-openssl.c index c263ba1..1f12f11 100644 --- a/trust/extract-openssl.c +++ b/trust/extract-openssl.c @@ -672,6 +672,7 @@ p11_extract_openssl_directory (P11KitIter *iter, free (filename); free (path); + free (name); } if (!ret) diff --git a/trust/index.c b/trust/index.c index 83f0dc0..83a4503 100644 --- a/trust/index.c +++ b/trust/index.c @@ -352,6 +352,7 @@ index_build (p11_index *index, count = nmerge; memcpy (built, merge, sizeof (CK_ATTRIBUTE) * nmerge); + p11_array_push (stack, merge); merge_attrs (built, &count, *attrs, nattrs, stack); merge_attrs (built, &count, extra, nextra, stack); @@ -367,7 +368,6 @@ index_build (p11_index *index, free (stack->elem[i]); *attrs = built; } else { - p11_attrs_free (merge); p11_attrs_free (extra); free (built); } diff --git a/trust/parser.c b/trust/parser.c index 4129cc0..54d9c15 100644 --- a/trust/parser.c +++ b/trust/parser.c @@ -676,6 +676,7 @@ p11_parser_free (p11_parser *parser) return_if_fail (parser != NULL); p11_persist_free (parser->persist); p11_array_free (parser->parsed); + p11_array_free (parser->formats); if (parser->asn1_owned) p11_dict_free (parser->asn1_defs); free (parser); diff --git a/trust/tests/Makefile.am b/trust/tests/Makefile.am index 5a6c9ec..53775df 100644 --- a/trust/tests/Makefile.am +++ b/trust/tests/Makefile.am @@ -37,6 +37,12 @@ LDADD = \ CHECK_PROGS = \ test-digest \ + test-asn1 \ + test-base64 \ + test-pem \ + test-oid \ + test-utf8 \ + test-x509 \ test-persist \ test-index \ test-parser \ @@ -48,12 +54,6 @@ CHECK_PROGS = \ test-cer \ test-bundle \ test-openssl \ - test-asn1 \ - test-base64 \ - test-pem \ - test-oid \ - test-utf8 \ - test-x509 \ $(NULL) noinst_PROGRAMS = \ diff --git a/trust/tests/test-asn1.c b/trust/tests/test-asn1.c index d5ec131..df75dfd 100644 --- a/trust/tests/test-asn1.c +++ b/trust/tests/test-asn1.c @@ -142,10 +142,11 @@ test_asn1_free (void) asn = p11_asn1_decode (defs, "PKIX1.ExtKeyUsageSyntax", test_eku_server_and_client, sizeof (test_eku_server_and_client), NULL); - assert_ptr_not_null (defs); + assert_ptr_not_null (asn); p11_asn1_free (asn); p11_asn1_free (NULL); + p11_dict_free (defs); } int diff --git a/trust/tests/test-builder.c b/trust/tests/test-builder.c index 1d37924..6e061aa 100644 --- a/trust/tests/test-builder.c +++ b/trust/tests/test-builder.c @@ -766,6 +766,7 @@ test_valid_dates (void) rv = p11_builder_build (test.builder, test.index, attrs, input, &extra); assert_num_eq (CKR_OK, rv); + p11_attrs_free (extra); p11_attrs_free (attrs); attrs = NULL; @@ -773,6 +774,7 @@ test_valid_dates (void) rv = p11_builder_build (test.builder, test.index, attrs, input, &extra); assert_num_eq (CKR_OK, rv); + p11_attrs_free (extra); p11_attrs_free (attrs); } @@ -831,6 +833,7 @@ test_valid_name (void) rv = p11_builder_build (test.builder, test.index, attrs, input, &extra); assert_num_eq (CKR_OK, rv); + p11_attrs_free (extra); p11_attrs_free (attrs); attrs = NULL; @@ -839,6 +842,7 @@ test_valid_name (void) rv = p11_builder_build (test.builder, test.index, attrs, input, &extra); assert_num_eq (CKR_OK, rv); + p11_attrs_free (extra); p11_attrs_free (attrs); } diff --git a/trust/token.c b/trust/token.c index 97b1fc0..1336443 100644 --- a/trust/token.c +++ b/trust/token.c @@ -396,6 +396,7 @@ p11_token_reload (p11_token *token, CK_ATTRIBUTE *attr; struct stat sb; char *origin; + bool ret; attr = p11_attrs_find (attrs, CKA_X_ORIGIN); if (attr == NULL) @@ -410,10 +411,14 @@ p11_token_reload (p11_token *token, } else { p11_message_err (errno, "cannot access trust file: %s", origin); } - return false; + ret = false; + + } else { + ret = loader_load_file (token, origin, &sb) > 0; } - return loader_load_file (token, origin, &sb) > 0; + free (origin); + return ret; } static bool @@ -676,6 +681,7 @@ on_index_store (void *data, p11_buffer_uninit (&buffer); p11_persist_free (persist); + free (other); if (rv == CKR_OK) { if (!p11_save_finish_file (file, &path, true)) |