From 06855553f26606830b91ac1726aa0fbd05e36721 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 10 2020 00:26:51 +0000 Subject: Prepare for a new update Reverting patches so we can apply the latest update and changes can be seen in the spec file and sources. --- diff --git a/common/attrs.c b/common/attrs.c index a387a66..aa91891 100644 --- a/common/attrs.c +++ b/common/attrs.c @@ -538,10 +538,8 @@ buffer_append_printf (p11_buffer *buffer, va_list va; va_start (va, format); - if (vasprintf (&string, format, va) < 0) { - va_end (va); + if (vasprintf (&string, format, va) < 0) return_if_reached (); - } va_end (va); p11_buffer_add (buffer, string, -1); diff --git a/common/compat.c b/common/compat.c index d1bd5aa..f0e31eb 100644 --- a/common/compat.c +++ b/common/compat.c @@ -525,10 +525,7 @@ strconcat (const char *first, for (arg = first; arg; arg = va_arg (va, const char*)) { size_t old_length = length; length += strlen (arg); - if (length < old_length) { - va_end (va); - return_val_if_reached (NULL); - } + return_val_if_fail (length >= old_length, NULL); } va_end (va); diff --git a/common/debug.h b/common/debug.h index 7ea36f3..255c62c 100644 --- a/common/debug.h +++ b/common/debug.h @@ -71,13 +71,13 @@ void p11_debug_precond (const char *format, #endif #define return_val_if_fail(x, v) \ - do { if (x) { } else { \ + do { if (!(x)) { \ p11_debug_precond ("p11-kit: '%s' not true at %s\n", #x, __func__); \ return v; \ } } while (false) #define return_if_fail(x) \ - do { if (x) { } else { \ + do { if (!(x)) { \ p11_debug_precond ("p11-kit: '%s' not true at %s\n", #x, __func__); \ return; \ } } while (false) @@ -100,7 +100,7 @@ void p11_debug_precond (const char *format, } while (false) #define warn_if_fail(x) \ - do { if (x) { } else { \ + do { if (!(x)) { \ p11_debug_precond ("p11-kit: '%s' not true at %s\n", #x, __func__); \ } } while (false) diff --git a/common/path.c b/common/path.c index 17a6230..5cf0e1a 100644 --- a/common/path.c +++ b/common/path.c @@ -218,10 +218,7 @@ p11_path_build (const char *path, while (path != NULL) { size_t old_len = len; len += strlen (path) + 1; - if (len < old_len) { - va_end (va); - return_val_if_reached (NULL); - } + return_val_if_fail (len >= old_len, NULL); path = va_arg (va, const char *); } va_end (va); diff --git a/p11-kit/iter.c b/p11-kit/iter.c index d1ffd91..0e4ca6e 100644 --- a/p11-kit/iter.c +++ b/p11-kit/iter.c @@ -157,10 +157,7 @@ p11_kit_iter_new (P11KitUri *uri, return_val_if_fail (iter != NULL, NULL); iter->modules = p11_array_new (NULL); - if (iter->modules == NULL) { - p11_kit_iter_free (iter); - return_val_if_reached (NULL); - } + return_val_if_fail (iter->modules != NULL, NULL); iter->want_writable = !!(behavior & P11_KIT_ITER_WANT_WRITABLE); iter->preload_results = !(behavior & P11_KIT_ITER_BUSY_SESSIONS); diff --git a/p11-kit/modules.c b/p11-kit/modules.c index db66b9a..4604e6e 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -780,16 +780,14 @@ init_globals_unlocked (void) static void free_modules_when_no_refs_unlocked (void) { - if (gl.modules) { - Module *mod; - p11_dictiter iter; - - /* Check if any modules have a ref count */ - p11_dict_iterate (gl.modules, &iter); - while (p11_dict_next (&iter, (void **)&mod, NULL)) { - if (mod->ref_count) - return; - } + Module *mod; + p11_dictiter iter; + + /* Check if any modules have a ref count */ + p11_dict_iterate (gl.modules, &iter); + while (p11_dict_next (&iter, (void **)&mod, NULL)) { + if (mod->ref_count) + return; } p11_dict_free (gl.unmanaged_by_funcs); diff --git a/p11-kit/proxy.c b/p11-kit/proxy.c index 8eaf205..b7fb63d 100644 --- a/p11-kit/proxy.c +++ b/p11-kit/proxy.c @@ -267,10 +267,7 @@ proxy_create (Proxy **res, CK_FUNCTION_LIST **loaded, py->forkid = p11_forkid; py->inited = modules_dup (loaded); - if (py->inited == NULL) { - proxy_free (py, 0); - return_val_if_reached (CKR_HOST_MEMORY); - } + return_val_if_fail (py->inited != NULL, CKR_HOST_MEMORY); rv = p11_kit_modules_initialize (py->inited, NULL); @@ -307,10 +304,7 @@ proxy_create (Proxy **res, CK_FUNCTION_LIST **loaded, break; } py->mappings[py->n_mappings].funcs = funcs; - py->mappings[py->n_mappings].wrap_slot = - (n_mappings == 0 || j == n_mappings) ? - py->n_mappings + MAPPING_OFFSET : - mappings[j].wrap_slot; + py->mappings[py->n_mappings].wrap_slot = j == n_mappings ? py->n_mappings + MAPPING_OFFSET : mappings[j].wrap_slot; py->mappings[py->n_mappings].real_slot = slots[i]; ++py->n_mappings; } @@ -326,10 +320,7 @@ proxy_create (Proxy **res, CK_FUNCTION_LIST **loaded, } py->sessions = p11_dict_new (p11_dict_ulongptr_hash, p11_dict_ulongptr_equal, NULL, free); - if (py->sessions == NULL) { - proxy_free (py, 1); - return_val_if_reached (CKR_HOST_MEMORY); - } + return_val_if_fail (py->sessions != NULL, CKR_HOST_MEMORY); py->refs = 1; *res = py; @@ -615,8 +606,7 @@ proxy_C_OpenSession (CK_X_FUNCTION_LIST *self, sess->wrap_slot = map.wrap_slot; sess->real_session = *handle; sess->wrap_session = ++state->last_handle; /* TODO: Handle wrapping, and then collisions */ - if (!p11_dict_set (state->px->sessions, &sess->wrap_session, sess)) - warn_if_reached (); + p11_dict_set (state->px->sessions, &sess->wrap_session, sess); *handle = sess->wrap_session; } diff --git a/p11-kit/rpc-client.c b/p11-kit/rpc-client.c index e202e37..0dd4525 100644 --- a/p11-kit/rpc-client.c +++ b/p11-kit/rpc-client.c @@ -371,8 +371,7 @@ proto_read_ulong_array (p11_rpc_message *msg, CK_ULONG_PTR arr, /* We need to go ahead and read everything in all cases */ for (i = 0; i < num; ++i) { - if (!p11_rpc_buffer_get_uint64 (msg->input, &msg->parsed, &val)) - return PARSE_ERROR; + p11_rpc_buffer_get_uint64 (msg->input, &msg->parsed, &val); if (arr) arr[i] = (CK_ULONG)val; } diff --git a/p11-kit/rpc-server.c b/p11-kit/rpc-server.c index 3216742..2db3524 100644 --- a/p11-kit/rpc-server.c +++ b/p11-kit/rpc-server.c @@ -2219,10 +2219,6 @@ p11_kit_remote_serve_tokens (const char **tokens, filter = p11_dict_get (filters, module); if (filter == NULL) { lower = calloc (1, sizeof (p11_virtual)); - if (lower == NULL) { - error = ENOMEM; - goto out; - } p11_virtual_init (lower, &p11_virtual_base, module, NULL); filter = p11_filter_subclass (lower, NULL); if (filter == NULL) { @@ -2230,11 +2226,7 @@ p11_kit_remote_serve_tokens (const char **tokens, p11_message_err (error, "couldn't subclass filter"); goto out; } - if (!p11_dict_set (filters, module, filter)) { - error = EINVAL; - p11_message_err (error, "couldn't register filter"); - goto out; - } + p11_dict_set (filters, module, filter); } for (i = 0; i < n_tokens; i++) { @@ -2289,11 +2281,6 @@ p11_kit_remote_serve_tokens (const char **tokens, p11_kit_modules_release (modules); if (error != 0) errno = error; - if (uris) { - for (i = 0; i < n_tokens; i++) - p11_kit_uri_free (uris[i]); - free (uris); - } return ret; } diff --git a/p11-kit/virtual.c b/p11-kit/virtual.c index 338239f..6abfe7a 100644 --- a/p11-kit/virtual.c +++ b/p11-kit/virtual.c @@ -2832,14 +2832,9 @@ p11_virtual_wrap (p11_virtual *virt, p11_destroyer destroyer) { Wrapper *wrapper; - CK_FUNCTION_LIST *result; return_val_if_fail (virt != NULL, NULL); - result = p11_virtual_wrap_fixed (virt, destroyer); - if (result) - return result; - wrapper = calloc (1, sizeof (Wrapper)); return_val_if_fail (wrapper != NULL, NULL); @@ -2849,10 +2844,8 @@ p11_virtual_wrap (p11_virtual *virt, wrapper->bound.version.minor = CRYPTOKI_VERSION_MINOR; wrapper->fixed_index = -1; - if (!init_wrapper_funcs (wrapper)) { - free (wrapper); - return_val_if_reached (NULL); - } + if (!init_wrapper_funcs (wrapper)) + return p11_virtual_wrap_fixed (virt, destroyer); assert ((void *)wrapper == (void *)&wrapper->bound); assert (p11_virtual_is_wrapper (&wrapper->bound)); @@ -2866,11 +2859,7 @@ CK_FUNCTION_LIST * p11_virtual_wrap (p11_virtual *virt, p11_destroyer destroyer) { - CK_FUNCTION_LIST *result; - - result = p11_virtual_wrap_fixed (virt, destroyer); - return_val_if_fail (result != NULL, NULL); - return result; + return p11_virtual_wrap_fixed (virt, destroyer); } #endif /* !FFI_CLOSURES */ @@ -3079,6 +3068,8 @@ p11_virtual_wrap_fixed (p11_virtual *virt, } p11_mutex_unlock (&p11_virtual_mutex); + return_val_if_fail (result != NULL, NULL); + return result; } diff --git a/trust/asn1.c b/trust/asn1.c index 5ce682d..dd1812d 100644 --- a/trust/asn1.c +++ b/trust/asn1.c @@ -285,17 +285,11 @@ p11_asn1_cache_new (void) return_val_if_fail (cache != NULL, NULL); cache->defs = p11_asn1_defs_load (); - if (cache->defs == NULL) { - p11_asn1_cache_free (cache); - return_val_if_reached (NULL); - } + return_val_if_fail (cache->defs != NULL, NULL); cache->items = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, free_asn1_item); - if (cache->items == NULL) { - p11_asn1_cache_free (cache); - return_val_if_reached (NULL); - } + return_val_if_fail (cache->items != NULL, NULL); return cache; } @@ -348,10 +342,7 @@ p11_asn1_cache_take (p11_asn1_cache *cache, item->length = der_len; item->node = node; item->struct_name = strdup (struct_name); - if (item->struct_name == NULL) { - free_asn1_item (item); - return_if_reached (); - } + return_if_fail (item->struct_name != NULL); if (!p11_dict_set (cache->items, (void *)der, item)) return_if_reached (); diff --git a/trust/builder.c b/trust/builder.c index d819dc8..742c544 100644 --- a/trust/builder.c +++ b/trust/builder.c @@ -187,10 +187,7 @@ p11_builder_new (int flags) return_val_if_fail (builder != NULL, NULL); builder->asn1_cache = p11_asn1_cache_new (); - if (builder->asn1_cache == NULL) { - p11_builder_free (builder); - return_val_if_reached (NULL); - } + return_val_if_fail (builder->asn1_cache, NULL); builder->asn1_defs = p11_asn1_cache_defs (builder->asn1_cache); builder->flags = flags; diff --git a/trust/index.c b/trust/index.c index 2d1da29..f4b6b4b 100644 --- a/trust/index.c +++ b/trust/index.c @@ -170,16 +170,10 @@ p11_index_new (p11_index_build_cb build, index->objects = p11_dict_new (p11_dict_ulongptr_hash, p11_dict_ulongptr_equal, NULL, free_object); - if (index->objects == NULL) { - p11_index_free (index); - return_val_if_reached (NULL); - } + return_val_if_fail (index->objects != NULL, NULL); index->buckets = calloc (NUM_BUCKETS, sizeof (index_bucket)); - if (index->buckets == NULL) { - p11_index_free (index); - return_val_if_reached (NULL); - } + return_val_if_fail (index->buckets != NULL, NULL); return index; } @@ -193,11 +187,9 @@ p11_index_free (p11_index *index) p11_dict_free (index->objects); p11_dict_free (index->changes); - if (index->buckets) { - for (i = 0; i < NUM_BUCKETS; i++) - free (index->buckets[i].elem); - free (index->buckets); - } + for (i = 0; i < NUM_BUCKETS; i++) + free (index->buckets[i].elem); + free (index->buckets); free (index); } diff --git a/trust/module.c b/trust/module.c index 24cda87..e09113b 100644 --- a/trust/module.c +++ b/trust/module.c @@ -1321,8 +1321,7 @@ find_objects_match (CK_ATTRIBUTE *attrs, } value = memdup (oid->pValue, oid->ulValueLen); return_val_if_fail (value != NULL, false); - if (!p11_dict_set (find->extensions, value, value)) - warn_if_reached (); + p11_dict_set (find->extensions, value, value); } } diff --git a/trust/parser.c b/trust/parser.c index e912c3a..f92cdc9 100644 --- a/trust/parser.c +++ b/trust/parser.c @@ -697,10 +697,8 @@ p11_parser_formats (p11_parser *parser, func = va_arg (va, parser_func); if (func == NULL) break; - if (!p11_array_push (formats, func)) { - va_end (va); + if (!p11_array_push (formats, func)) return_if_reached (); - } } va_end (va); diff --git a/trust/persist.c b/trust/persist.c index 569cea1..887b316 100644 --- a/trust/persist.c +++ b/trust/persist.c @@ -89,10 +89,7 @@ p11_persist_new (void) return_val_if_fail (persist != NULL, NULL); persist->constants = p11_constant_reverse (true); - if (persist->constants == NULL) { - free (persist); - return_val_if_reached (NULL); - } + return_val_if_fail (persist->constants != NULL, NULL); return persist; } diff --git a/trust/save.c b/trust/save.c index bb77348..abff864 100644 --- a/trust/save.c +++ b/trust/save.c @@ -68,8 +68,6 @@ static char * make_unique_name (const char *bare, const char *extension, int (*check) (void *, char *), void *data); -static void filo_free (p11_save_file *file); -static void dir_free (p11_save_dir *dir); bool p11_save_write_and_finish (p11_save_file *file, @@ -95,7 +93,6 @@ p11_save_open_file (const char *path, { p11_save_file *file; char *temp; - mode_t mode; int fd; return_val_if_fail (path != NULL, NULL); @@ -106,9 +103,7 @@ p11_save_open_file (const char *path, if (asprintf (&temp, "%s%s.XXXXXX", path, extension) < 0) return_val_if_reached (NULL); - mode = umask (0077); fd = mkstemp (temp); - umask (mode); if (fd < 0) { p11_message_err (errno, "couldn't create file: %s%s", path, extension); free (temp); @@ -119,15 +114,9 @@ p11_save_open_file (const char *path, return_val_if_fail (file != NULL, NULL); file->temp = temp; file->bare = strdup (path); - if (file->bare == NULL) { - filo_free (file); - return_val_if_reached (NULL); - } + return_val_if_fail (file->bare != NULL, NULL); file->extension = strdup (extension); - if (file->extension == NULL) { - filo_free (file); - return_val_if_reached (NULL); - } + return_val_if_fail (file->extension != NULL, NULL); file->flags = flags; file->fd = fd; @@ -177,13 +166,6 @@ filo_free (p11_save_file *file) free (file); } -static void -dir_free (p11_save_dir *dir) { - p11_dict_free (dir->cache); - free (dir->path); - free (dir); -} - #ifdef OS_UNIX static int @@ -367,16 +349,10 @@ p11_save_open_directory (const char *path, return_val_if_fail (dir != NULL, NULL); dir->path = strdup (path); - if (dir->path == NULL) { - dir_free (dir); - return_val_if_reached (NULL); - } + return_val_if_fail (dir->path != NULL, NULL); dir->cache = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, free, NULL); - if (dir->cache == NULL) { - dir_free (dir); - return_val_if_reached (NULL); - } + return_val_if_fail (dir->cache != NULL, NULL); dir->flags = flags; return dir; diff --git a/trust/session.c b/trust/session.c index d464394..b93a5c3 100644 --- a/trust/session.c +++ b/trust/session.c @@ -59,18 +59,12 @@ p11_session_new (p11_token *token) session->handle = p11_module_next_id (); session->builder = p11_builder_new (P11_BUILDER_FLAG_NONE); - if (session->builder == NULL) { - p11_session_free (session); - return_val_if_reached (NULL); - } + return_val_if_fail (session->builder, NULL); session->index = p11_index_new (p11_builder_build, NULL, NULL, p11_builder_changed, session->builder); - if (session->index == NULL) { - p11_session_free (session); - return_val_if_reached (NULL); - } + return_val_if_fail (session->index != NULL, NULL); session->token = token; diff --git a/trust/token.c b/trust/token.c index fd3b043..4cbcc77 100644 --- a/trust/token.c +++ b/trust/token.c @@ -829,10 +829,7 @@ p11_token_new (CK_SLOT_ID slot, return_val_if_fail (token != NULL, NULL); token->builder = p11_builder_new (P11_BUILDER_FLAG_TOKEN); - if (token->builder == NULL) { - p11_token_free (token); - return_val_if_reached (NULL); - } + return_val_if_fail (token->builder != NULL, NULL); token->index = p11_index_new (on_index_build, on_index_store,