coccinelle: increase coverage by the coccinelle checker (#43412)

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-18 13:16:06 +02:00
committed by GitHub
45 changed files with 288 additions and 45 deletions
+6 -1
View File
@@ -12,10 +12,14 @@
* assert(param) at the top. If it can legitimately be NULL, add an if() guard.
*/
@@
/* exec_invoke() is too large to be checked by this rule. */
position p : script:python() {
not (p[0].file.endswith("exec-invoke.c") and
p[0].current_element == "exec_invoke")
};
identifier fn, param;
identifier is_set =~ "_is_set$";
type T;
position p;
@@
fn(..., T *param, ...) {
@@ -24,6 +28,7 @@ fn(..., T *param, ...) {
when != assert_se(param)
when != assert_se(param != NULL)
when != assert_return(param, ...)
when != bus_assert_return(param, ...)
when != ASSERT_PTR(param)
when != POINTER_MAY_BE_NULL(param)
/* Any foo_is_set(param) guard implies param != NULL, since all *_is_set()
+108 -4
View File
@@ -58,27 +58,95 @@
#define TEST(x, ...) static void test_##x(void)
#define TEST_RET(x, ...) static int test_##x(void)
/* Coccinelle doesn't know this keyword, so just drop it, since it's not important for any of our rules. */
/* Coccinelle doesn't know these keywords, so just drop them, since they are not important for any of our rules. */
#define thread_local
#define _Noreturn
/* Coccinelle can't handle the __attribute__((__cleanup__(x))) GCC extension used by our _cleanup_*
* macros. Without this, any variable declared with _cleanup_free_ or _cleanup_(foo) makes the whole
* function unparsable. Drop the attribute since it's not relevant for semantic checks. */
#define _cleanup_bitmap_free_
#define _cleanup_close_
#define _cleanup_close_pair_
#define _cleanup_closedir_
#define _cleanup_fclose_
#define _cleanup_fdset_free_
#define _cleanup_file_close_
#define _cleanup_free_
#define _cleanup_freecon_
#define _cleanup_hashmap_free_
#define _cleanup_iterated_cache_free_
#define _cleanup_ordered_hashmap_free_
#define _cleanup_ordered_set_free_
#define _cleanup_pages_
#define _cleanup_pclose_
#define _cleanup_set_free_
#define _cleanup_strv_free_
#define _cleanup_strv_free_erase_
#define _cleanup_umask_
/* Also drop other attributes. */
/* fundmental/macro.h */
#define _alias_(x)
#define _align_(x)
#define _alignas_(x)
#define _alignptr_
#define _cleanup_(x)
#define _const_
#define _deprecated_
#define _destructor_
#define _hidden_
#define _likely_(x) x
#define _malloc_
#define _noclone_
#define _noinline_
#define _noreturn_
#define _packed_
#define _printf_(a, b)
#define _public_
#define _pure_
#define _returns_nonnull_
#define _section_(x)
#define _sentinel_
#define _unlikely_(x) x
#define _unused_
#define _used_
#define _warn_unused_result_
#define _weak_
#define _weakref_(x)
#define _alloc_(...)
#define _fallthrough_
#define _retain_
#define _no_reorder_
#define _nonnull_if_nonzero_(p, n)
/* basic/dlopen-note.h */
#define _dlopen_loader_
/* basic/macro.h */
#define _variable_no_sanitize_address_
#define _function_no_sanitize_float_cast_overflow_
/* systemd/_sd-common.h */
#define _sd_printf_(a, b)
#define _sd_sentinel_
#define _sd_packed_
#define _sd_pure_
#define _sd_deprecated_
/* Coccinelle fails to parse these from the included headers, so let's just drop them. */
#define PAM_EXTERN
#define STACK_OF(x)
/* Mark a couple of iterator explicitly as iterators, otherwise Coccinelle gets a bit confused. Coccinelle
* can usually infer this information automagically, but in these specific cases it needs a bit of help. */
#define FOREACH_ARGUMENT(entry, ...) YACFE_ITERATOR
#define FOREACH_ARRAY(i, array, num) YACFE_ITERATOR
#define FOREACH_DIRENT(de, d, on_error) YACFE_ITERATOR
#define FOREACH_DIRENT_ALL(de, d, on_error) YACFE_ITERATOR
#define FOREACH_DIRENT(de, d, on_error) for (struct dirent *(de) = readdir_ensure_type(d); (de); (de) = readdir_ensure_type(d))
#define FOREACH_DIRENT_ALL(de, d, on_error) FOREACH_DIRENT(de, d, on_error)
#define FOREACH_DIRENT_IN_BUFFER(de, buf, sz) YACFE_ITERATOR
#define FOREACH_ELEMENT(i, array) YACFE_ITERATOR
#define FOREACH_INOTIFY_EVENT_WARN(e, buffer, sz) YACFE_ITERATOR
#define FOREACH_PCR_IN_TPMS_PCR_SELECTION(pcr, tpms) YACFE_ITERATOR
#define FOREACH_STRING(x, y, ...) YACFE_ITERATOR
#define HASHMAP_FOREACH(e, h) YACFE_ITERATOR
#define HASHMAP_FOREACH_KEY(e, k, h) YACFE_ITERATOR
@@ -88,11 +156,13 @@
#define NULSTR_FOREACH_PAIR(i, j, l) YACFE_ITERATOR
#define ORDERED_HASHMAP_FOREACH(e, h) YACFE_ITERATOR
#define ORDERED_HASHMAP_FOREACH_KEY(e, k, h) YACFE_ITERATOR
#define SD_FIBER_WITH_TIMEOUT(timeout) YACFE_ITERATOR
#define SET_FOREACH(e, s) YACFE_ITERATOR
#define SET_FOREACH_MOVE(e, d, s) YACFE_ITERATOR
#define STRV_FOREACH(s, l) YACFE_ITERATOR
#define STRV_FOREACH_BACKWARDS(s, l) YACFE_ITERATOR
#define STRV_FOREACH_PAIR(x, y, l) YACFE_ITERATOR
#define WITH_UMASK(mask) YACFE_ITERATOR
/* Coccinelle really doesn't like multiline macros that are not in the "usual" do { ... } while(0) format, so
* let's help it a little here by providing simplified one-line versions. */
@@ -108,3 +178,37 @@
* See: https://github.com/coccinelle/coccinelle/issues/413 */
#define Z_EXPORT
#define Z_EXTERN
/* Ignore several more macros */
#define BUS_ERROR_MAP_ELF_REGISTER
#define UPPERCASE_LETTERS ""
#define LOWERCASE_LETTERS ""
#define DIGITS ""
#define ANSI_DCS ""
#define ANSI_ST ""
#define TPM2_SHA256_DIGEST_SIZE 32
#define ElfW(type) Elf__ELF_NATIVE_CLASS_##type
#define STACK_OF(type) struct stack_st_##type
/* shared/options.h */
#define _OPTION_COCCI_ case (0x100 + counter)
#define OPTION_NAMESPACE(ns) _OPTION_COCCI_
#define OPTION_GROUP(gr) _OPTION_COCCI_
#define OPTION_FULL_DATA(fl, sc, lc, mv, d, h) _OPTION_COCCI_
#define OPTION_FULL(fl, sc, lc, mv, h) _OPTION_COCCI_
#define OPTION(sc, lc, mv, h) _OPTION_COCCI_
#define OPTION_LONG(lc, mv, h) _OPTION_COCCI_
#define OPTION_LONG_FLAGS(fl, lc, mv, h) _OPTION_COCCI_
#define OPTION_LONG_DATA(lc, mv, d, h) _OPTION_COCCI_
#define OPTION_SHORT(sc, mv, h) _OPTION_COCCI_
#define OPTION_SHORT_FLAGS(fl, sc, mv, h) _OPTION_COCCI_
#define OPTION_SHORT_DATA(sc, mv, d, h) _OPTION_COCCI_
#define OPTION_POSITIONAL _OPTION_COCCI_
#define OPTION_HELP_VERBATIM(lc, h) _OPTION_COCCI_
#define OPTION_COMMON_PRIVATE_KEY(purpose) _OPTION_COCCI_
#define OPTION_COMMON_CERTIFICATE(purpose) _OPTION_COCCI_
/* libbpf */
#define SEC(x)
#define __weak
#define __ksym
+1 -1
View File
@@ -2907,7 +2907,7 @@ if spatch.found()
args : [meson.project_source_root() / dir,
meson.project_source_root() / 'coccinelle'],
suite : 'coccinelle',
timeout : 120,
timeout : 300,
)
endif
endforeach
+5
View File
@@ -92,6 +92,10 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
UnitTimes *times;
BootTimes *boot;
assert(bus);
assert(name);
assert(units);
if (strv_extend(units, name))
return log_oom();
@@ -163,6 +167,7 @@ static int list_dependencies(sd_bus *bus, const char *name) {
BootTimes *boot;
assert(bus);
assert(name);
path = unit_dbus_path_from_name(name);
if (!path)
+2
View File
@@ -96,6 +96,8 @@ static int mangle_patterns(char **args, char ***ret) {
_cleanup_strv_free_ char **mangled = NULL;
int r;
assert(ret);
STRV_FOREACH(arg, args) {
char *t;
+1 -1
View File
@@ -117,9 +117,9 @@ static int cat_config(char **files) {
}
static int parse_argv(int argc, char *argv[], char ***ret_args) {
assert(argc >= 0);
assert(argv);
assert(ret_args);
OptionParser opts = { argc, argv };
+1
View File
@@ -58,6 +58,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
assert(argc >= 0);
assert(argv);
assert(ret_args);
OptionParser opts = { argc, argv };
+2
View File
@@ -91,6 +91,8 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) {
_cleanup_close_ int pin_fd = -EBADF;
int r;
assert(ret);
r = sd_bus_new(&bus);
if (r < 0)
return log_error_errno(r, "Failed to allocate bus: %m");
+3 -1
View File
@@ -162,10 +162,12 @@ static int bus_job_find(sd_bus *bus, const char *path, const char *interface, vo
static int bus_job_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *reterr_error) {
_cleanup_strv_free_ char **l = NULL;
Manager *m = userdata;
Manager *m = ASSERT_PTR(userdata);
unsigned k = 0;
Job *j;
assert(nodes);
l = new0(char*, hashmap_size(m->jobs)+1);
if (!l)
return -ENOMEM;
+3 -1
View File
@@ -413,10 +413,12 @@ static int bus_kill_context_find(sd_bus *bus, const char *path, const char *inte
static int bus_unit_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *reterr_error) {
_cleanup_strv_free_ char **l = NULL;
Manager *m = userdata;
Manager *m = ASSERT_PTR(userdata);
unsigned k = 0;
Unit *u;
assert(nodes);
l = new0(char*, hashmap_size(m->units)+1);
if (!l)
return -ENOMEM;
+3
View File
@@ -174,6 +174,9 @@ static int pick_uid(char **suggested_paths, const char *name, uid_t *ret_uid) {
0x8a, 0xbb, 0x39, 0x57, 0x8d, 0xd9, 0xec, 0x59
};
assert(name);
assert(ret_uid);
unsigned n_tries = 100, current_suggested = 0;
int r;
+46 -20
View File
@@ -518,6 +518,7 @@ static int setup_output(
assert(context);
assert(params);
assert(named_iofds);
assert(ident);
assert(journal_stream_dev);
assert(journal_stream_ino);
@@ -684,6 +685,7 @@ static int setup_confirm_stdio(
int r;
assert(context);
assert(vc);
assert(ret_saved_stdin);
assert(ret_saved_stdout);
@@ -742,6 +744,7 @@ static void write_confirm_error(int err, const char *vc, const char *unit_id) {
_cleanup_close_ int fd = -EBADF;
assert(vc);
assert(unit_id);
fd = open_terminal(vc, O_WRONLY|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
@@ -789,6 +792,7 @@ static int ask_for_confirmation(const ExecContext *context, const ExecParameters
assert(context);
assert(params);
assert(cmdline);
/* For any internal errors, assume a positive response. */
r = setup_confirm_stdio(context, params->confirm_spawn, &saved_stdin, &saved_stdout);
@@ -965,6 +969,8 @@ static int get_supplementary_groups(
static int enforce_groups(gid_t gid, const gid_t *supplementary_gids, int ngids) {
int r;
assert(supplementary_gids || ngids == 0);
/* Handle SupplementaryGroups= if it is not empty */
if (ngids > 0) {
r = maybe_setgroups(ngids, supplementary_gids);
@@ -1063,6 +1069,7 @@ static int ask_password_conv(
assert(msg);
assert(data->context);
assert(data->params);
assert(ret);
size_t n = num_msg;
struct pam_response *responses = new0(struct pam_response, n);
@@ -1166,7 +1173,7 @@ static int attach_to_subcgroup(
const ExecContext *context,
const CGroupContext *cgroup_context,
const ExecParameters *params,
const char *prefix) {
const char *prefix) { /* may be NULL */
_cleanup_free_ char *subgroup = NULL;
int r;
@@ -1300,6 +1307,7 @@ static int setup_pam(
int flags = 0;
assert(context);
assert(cgroup_context);
assert(params);
assert(user);
assert(uid_is_valid(uid));
@@ -1987,9 +1995,9 @@ static int build_environment(
const ExecContext *c,
const ExecParameters *p,
const CGroupContext *cgroup_context,
const char *home,
const char *username,
const char *shell,
const char *home, /* may be NULL */
const char *username, /* may be NULL */
const char *shell, /* may be NULL */
dev_t journal_stream_dev,
ino_t journal_stream_ino,
char *const *pressure_path,
@@ -2005,6 +2013,7 @@ static int build_environment(
assert(c);
assert(p);
assert(cgroup_context);
assert(pressure_path);
assert(ret);
exec_pid = needs_sandboxing && exec_needs_pid_namespace(c, p) ? 1 : getpid_cached();
@@ -2307,6 +2316,7 @@ static int bpffs_prepare(
_cleanup_close_pair_ int socket_fds[2] = EBADF_PAIR, errno_pipe[2] = EBADF_PAIR;
int r;
assert(c);
assert(ret_sock_fd);
assert(ret_pid);
assert(ret_errno_pipe);
@@ -2336,6 +2346,9 @@ static int bpffs_prepare(
static int setup_private_users_child(int unshare_ready_fd, const char *uid_map, const char *gid_map, bool allow_setgroups) {
int r;
assert(uid_map);
assert(gid_map);
/* Child process, running in the original user namespace. Let's update the parent's UID/GID map from
* here, after the parent opened its own user namespace. */
@@ -2373,14 +2386,14 @@ static int setup_private_users_child(int unshare_ready_fd, const char *uid_map,
}
static int setup_private_users(
sd_varlink *nsresource_link,
sd_varlink *nsresource_link, /* may be NULL */
PrivateUsers private_users,
uid_t saved_uid, /* service manager uid */
gid_t saved_gid, /* service manager gid */
uid_t *uid, /* unit uid (seen from inside) [input+output] */
gid_t *gid, /* unit gid (ditto) [input+output] */
uid_t *outside_uid, /* uid seen from the outside (which is the same as *uid, except of userns is used) */
gid_t *outside_gid, /* gid seen from the outside (similar) */
uid_t saved_uid, /* service manager uid */
gid_t saved_gid, /* service manager gid */
uid_t *uid, /* unit uid (seen from inside) [input+output] */
gid_t *gid, /* unit gid (ditto) [input+output] */
uid_t *outside_uid, /* uid seen from the outside (which is the same as *uid, except of userns is used) */
gid_t *outside_gid, /* gid seen from the outside (similar) */
bool allow_setgroups) {
_cleanup_free_ char *uid_map = NULL, *gid_map = NULL;
@@ -2703,6 +2716,7 @@ static int create_many_symlinks(const char *root, const char *source, char **sym
_cleanup_free_ char *src_abs = NULL;
int r;
assert(root);
assert(source);
src_abs = path_join(root, source);
@@ -3517,6 +3531,7 @@ static bool insist_on_sandboxing(
size_t n_bind_mounts) {
assert(context);
assert(rootfs);
assert(n_bind_mounts == 0 || bind_mounts);
/* Checks whether we need to insist on fs namespacing. i.e. whether we have settings configured that
@@ -3563,6 +3578,7 @@ static int setup_ephemeral(
assert(context);
assert(runtime);
assert(rootfs);
assert(reterr_path);
if (!rootfs->image && !rootfs->directory)
return 0;
@@ -3639,15 +3655,16 @@ static int setup_ephemeral(
static int verity_settings_prepare(
VeritySettings *verity,
const char *root_image,
const struct iovec *root_hash,
const char *root_hash_path,
const struct iovec *root_hash_sig,
const char *root_hash_sig_path,
const char *verity_data_path) {
const struct iovec *root_hash, /* may be NULL */
const char *root_hash_path, /* may be NULL */
const struct iovec *root_hash_sig, /* may be NULL */
const char *root_hash_sig_path, /* may be NULL */
const char *verity_data_path) { /* may be NULL */
int r;
assert(verity);
assert(root_image);
if (root_hash) {
iovec_done(&verity->root_hash);
@@ -3695,6 +3712,7 @@ static int pin_rootfs(
assert(context);
assert(params);
assert(ret);
assert(reterr_path);
if (!FLAGS_SET(params->flags, EXEC_APPLY_CHROOT)) {
*ret = PINNED_RESOURCE_NULL;
@@ -3841,7 +3859,7 @@ static int apply_mount_namespace(
PidRef *bpffs_pidref,
int bpffs_socket_fd,
int bpffs_errno_pipe,
sd_varlink *mountfsd_link,
sd_varlink *mountfsd_link, /* may be NULL */
char **reterr_path) {
_cleanup_(verity_settings_done) VeritySettings verity = VERITY_SETTINGS_DEFAULT;
@@ -3859,6 +3877,10 @@ static int apply_mount_namespace(
assert(context);
assert(params);
assert(runtime);
assert(rootfs);
assert(pressure_path);
assert(bpffs_pidref);
assert(reterr_path);
CLEANUP_ARRAY(bind_mounts, n_bind_mounts, bind_mount_free_many);
@@ -4091,8 +4113,8 @@ static int apply_working_directory(
const ExecContext *context,
const ExecParameters *params,
ExecRuntime *runtime,
const char *pwent_home,
char * const *env) {
const char *pwent_home, /* may be NULL */
char * const *env) { /* can be NULL */
const char *wd;
int r;
@@ -4572,6 +4594,7 @@ static void log_command_line(
assert(params);
assert(msg);
assert(executable);
assert(argv);
if (!DEBUG_LOGGING)
return;
@@ -4691,7 +4714,7 @@ static int setup_delegated_namespaces(
PidRef *bpffs_pidref,
int bpffs_socket_fd,
int bpffs_errno_pipe,
sd_varlink *mountfsd_link,
sd_varlink *mountfsd_link, /* may be NULL */
int *reterr_exit_status) {
int r;
@@ -4707,6 +4730,9 @@ static int setup_delegated_namespaces(
assert(params);
assert(runtime);
assert(rootfs);
assert(pressure_path);
assert(command);
assert(bpffs_pidref);
assert(reterr_exit_status);
if (exec_needs_network_namespace(context) &&
+1
View File
@@ -2511,6 +2511,7 @@ static int exec_shared_runtime_make(
assert(m);
assert(c);
assert(id);
assert(ret);
/* It is not necessary to create ExecSharedRuntime object. */
if (!c->user_namespace_path && !exec_needs_network_namespace(c) && !exec_needs_ipc_namespace(c) &&
+3
View File
@@ -198,6 +198,9 @@ static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) {
_cleanup_strv_free_ char **files = NULL, **dirs = NULL;
int r;
assert(ret_files);
assert(ret_dirs);
r = xdg_user_config_dir("/systemd", &base);
if (r < 0)
return r;
+2
View File
@@ -6923,6 +6923,8 @@ int unit_get_exec_quota_stats(Unit *u, ExecContext *c, ExecDirectoryType dt, uin
assert(u);
assert(c);
assert(ret_usage);
assert(ret_limit);
if (c->directories[dt].n_items == 0) {
*ret_usage = UINT64_MAX;
+6
View File
@@ -243,6 +243,12 @@ static int enumerate_dir_d(
char *c;
int r;
assert(top);
assert(bottom);
assert(drops);
assert(toppath);
assert(drop);
assert(!endswith(drop, "/"));
path = path_join(toppath, drop);
@@ -20,6 +20,8 @@ static int environment_dirs(char ***ret) {
_cleanup_free_ char *c = NULL;
int r;
assert(ret);
dirs = strv_new(CONF_PATHS("environment.d"));
if (!dirs)
return -ENOMEM;
+3 -1
View File
@@ -73,9 +73,11 @@ static int acquire_group_list(char ***ret) {
}
static int group_completion_callback(const char *key, GetCompletionsFlags flags, char ***ret_list, void *userdata) {
char ***available = userdata;
char ***available = ASSERT_PTR(userdata);
int r;
assert(ret_list);
if (!*available) {
r = acquire_group_list(available);
if (r < 0)
+3 -1
View File
@@ -552,12 +552,14 @@ static void home_set_state(Home *h, HomeState state) {
static int home_parse_worker_stdout(int _fd, UserRecord **ret) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
_cleanup_close_ int fd = _fd; /* take possession, even on failure */
_cleanup_close_ int fd = ASSERT_FD(TAKE_FD(_fd)); /* take possession, even on failure */
_cleanup_(user_record_unrefp) UserRecord *hr = NULL;
_cleanup_fclose_ FILE *f = NULL;
struct stat st;
int r;
assert(ret);
if (fstat(fd, &st) < 0)
return log_error_errno(errno, "Failed to stat stdout fd: %m");
+1
View File
@@ -1370,6 +1370,7 @@ static int home_create(UserRecord *h, Hashmap *blobs, UserRecord **ret_home) {
int r;
assert(h);
assert(ret_home);
if (!h->user_name)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "User record lacks name, refusing.");
+3 -1
View File
@@ -1486,10 +1486,12 @@ static int transfer_node_enumerator(
sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
Manager *m = userdata;
Manager *m = ASSERT_PTR(userdata);
Transfer *t;
unsigned k = 0;
assert(nodes);
l = new0(char*, hashmap_size(m->transfers) + 1);
if (!l)
return -ENOMEM;
+1 -1
View File
@@ -80,7 +80,7 @@ int sd_dhcp_client_set_anonymize(sd_dhcp_client *client, int b) {
assert_return(client, -EINVAL);
assert_return(!sd_dhcp_client_is_running(client), -EBUSY);
client->anonymize = !!b;
client->anonymize = b;
return 0;
}
+1 -1
View File
@@ -126,7 +126,7 @@ int sd_dhcp_relay_set_remote_id(sd_dhcp_relay *relay, const struct iovec *iov) {
int sd_dhcp_relay_set_server_identifier_override(sd_dhcp_relay *relay, int b) {
assert_return(relay, -EINVAL);
relay->server_identifier_override = !!b;
relay->server_identifier_override = b;
return 0;
}
@@ -70,6 +70,8 @@ static const char *extra_option_163 = "private_option_163";
static const char *extra_option_164 = "private_option_164";
static void setup(sd_event_io_handler_t io_handler, sd_dhcp_client_callback_t client_handler, sd_dhcp_client **ret) {
assert_se(ret);
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
ASSERT_OK(sd_event_new(&e));
ASSERT_NOT_NULL(e);
@@ -141,6 +141,7 @@ int journal_directory_vacuum(
CLEANUP_ARRAY(list, n_list, vacuum_info_array_free);
assert(directory);
POINTER_MAY_BE_NULL(oldest_usec);
if (max_use <= 0 && max_retention_usec <= 0 && n_max_files <= 0)
return 0;
+2
View File
@@ -3433,6 +3433,8 @@ _public_ int sd_journal_enumerate_unique(
assert_return(j, -EINVAL);
assert_return(!journal_origin_changed(j), -ECHILD);
assert_return(j->unique_field, -EINVAL);
assert_return(ret_data, -EINVAL);
assert_return(ret_size, -EINVAL);
k = strlen(j->unique_field);
+7 -4
View File
@@ -1081,12 +1081,15 @@ int sd_netlink_message_read_strv(sd_netlink_message *m, uint16_t container_type,
if (type != attr_type)
continue;
r = strv_extend(&s, RTA_DATA(rta));
if (r < 0)
return r;
if (ret) {
r = strv_extend(&s, RTA_DATA(rta));
if (r < 0)
return r;
}
}
*ret = TAKE_PTR(s);
if (ret)
*ret = TAKE_PTR(s);
return 0;
}
+9
View File
@@ -5318,6 +5318,15 @@ static int run_container(
assert_se(sigemptyset(&mask_chld) == 0);
assert_se(sigaddset(&mask_chld, SIGCHLD) == 0);
assert(runtime_dir);
assert(directory);
assert(veth_name);
assert(veth_created);
assert(expose_args);
assert(master);
assert(pid);
assert(ret);
/* Set up the unix export host directory on the host first */
r = setup_unix_export_dir_outside(runtime_dir, &unix_export_host_dir);
if (r < 0)
+1
View File
@@ -184,6 +184,7 @@ static int print_path(const char *n) {
static int parse_argv(int argc, char *argv[], char ***ret_args) {
assert(argc >= 0);
assert(argv);
assert(ret_args);
OptionParser opts = { argc, argv };
+3
View File
@@ -201,6 +201,9 @@ static int determine_matches(const char *image, char **l, bool allow_any, char *
_cleanup_strv_free_ char **k = NULL;
int r;
assert(image);
assert(ret);
/* Determine the matches to apply. If the list is empty we derive the match from the image name. If
* the list contains exactly the "-" we return a wildcard list (which is the empty list), but only if
* this is expressly permitted. */
+1
View File
@@ -1532,6 +1532,7 @@ static int print_configuration(DNSConfiguration *configuration, StatusMode mode,
int r;
assert(configuration);
POINTER_MAY_BE_NULL(empty_line);
pager_open(arg_pager_flags);
+4
View File
@@ -637,6 +637,10 @@ static int bus_append_exec_command(sd_bus_message *m, const char *field, const c
ExecCommandFlags flags = 0;
int r;
assert(m);
assert(field);
assert(eq);
do {
switch (*eq) {
+4
View File
@@ -2983,6 +2983,10 @@ static int normalize_linked_files(
_cleanup_strv_free_ char **files = NULL, **names = NULL;
int r;
assert(lp);
assert(ret_names);
assert(ret_files);
STRV_FOREACH(a, names_or_paths) {
_cleanup_(install_context_done) InstallContext ctx = { .scope = scope };
InstallInfo *i = NULL;
+2
View File
@@ -86,6 +86,8 @@ int get_keymaps(char ***ret) {
_cleanup_strv_free_ char **keymap_dirs = NULL;
int r;
assert(ret);
r = keymap_directories(&keymap_dirs);
if (r < 0)
return r;
+3 -3
View File
@@ -189,14 +189,14 @@ static int mcopy_flush_files(
const char *dest_rel,
char ***file_batch) {
_cleanup_strv_free_ char **argv = NULL, **batch = TAKE_PTR(*file_batch);
_cleanup_free_ char *dest = NULL;
assert(mcopy_bin);
assert(node);
assert(dest_rel);
assert(file_batch);
_cleanup_strv_free_ char **argv = NULL, **batch = TAKE_PTR(*file_batch);
_cleanup_free_ char *dest = NULL;
if (strv_isempty(batch))
return 0;
+2
View File
@@ -9585,6 +9585,8 @@ int tpm2_pcrlock_policy_from_credentials(
_cleanup_close_ int dfd = -EBADF;
int r;
assert(ret);
/* During boot we'll not have access to the pcrlock.json file in /var/. In order to support
* pcrlock-bound root file systems we'll store a copy of the JSON data, wrapped in an (plaintext)
* credential in the ESP or XBOOTLDR partition. There might be multiple of those however (because of
+10 -1
View File
@@ -384,6 +384,11 @@ int unit_file_build_name_map(
uint64_t timestamp_hash;
int r;
assert(lp);
POINTER_MAY_BE_NULL(cache_timestamp_hash);
assert(unit_ids_map);
assert(unit_names_map);
/* Before doing anything, check if the timestamp hash that was passed is still valid.
* If yes, do nothing. */
if (cache_timestamp_hash &&
@@ -635,6 +640,9 @@ int unit_file_remove_from_name_map(
int r;
assert(lp);
assert(unit_ids_map);
assert(unit_names_map);
assert(path);
/* This assumes the specified path is already removed, and drops the relevant entries from the maps. */
@@ -655,7 +663,8 @@ int unit_file_remove_from_name_map(
_unused_ _cleanup_free_ char *key = NULL;
free(hashmap_remove2(*unit_ids_map, name, (void**) &key));
string_strv_hashmap_remove(*unit_names_map, name, name);
free(set_remove(*path_cache, path));
if (path_cache)
free(set_remove(*path_cache, path));
return 0;
}
+5
View File
@@ -369,8 +369,13 @@ static int acquire_device_list(
sd_varlink **link,
char ***ret_menu,
char ***ret_accepted) {
int r;
assert(link);
assert(ret_menu);
assert(ret_accepted);
r = connect_to_repart(link);
if (r < 0)
return r;
+5 -2
View File
@@ -100,7 +100,7 @@ static bool output_show_machine(const char *name, char **patterns) {
static int get_machine_list(
sd_bus *bus,
struct machine_info **_machine_infos,
struct machine_info **ret_machine_infos,
char **patterns) {
struct machine_info *machine_infos = NULL;
@@ -108,6 +108,9 @@ static int get_machine_list(
_cleanup_free_ char *hn = NULL;
int c = 0, r;
assert(bus);
assert(ret_machine_infos);
hn = gethostname_malloc();
if (!hn)
return log_oom();
@@ -153,7 +156,7 @@ static int get_machine_list(
c++;
}
*_machine_infos = machine_infos;
*ret_machine_infos = machine_infos;
return c;
}
+5 -1
View File
@@ -519,8 +519,10 @@ int unit_find_paths(
*/
assert(unit_name);
assert(ret_fragment_path);
assert(lp);
assert(cached_id_map);
assert(cached_name_map);
assert(ret_fragment_path);
/* Go via the bus to acquire the path, unless we are explicitly told not to, or when the unit name is a template */
if (!force_client_side &&
@@ -529,6 +531,8 @@ int unit_find_paths(
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *load_state = NULL, *dbus_path = NULL;
assert(bus);
dbus_path = unit_dbus_path_from_name(unit_name);
if (!dbus_path)
return log_oom();
+6
View File
@@ -666,6 +666,8 @@ static int job_node_enumerator(
Job *j;
unsigned k = 0;
assert(nodes);
l = new0(char*, hashmap_size(m->jobs) + 1);
if (!l)
return -ENOMEM;
@@ -759,6 +761,8 @@ static int sysupdate_run_simple(sd_json_variant **ret, Target *t, ...) {
_cleanup_free_ char *target_arg = NULL;
int r;
assert(ret);
if (t) {
r = target_get_argument(t, &target_arg);
if (r < 0)
@@ -1617,6 +1621,8 @@ static int target_node_enumerator(
unsigned k = 0;
int r;
assert(nodes);
r = manager_ensure_targets(m);
if (r < 0)
return r;
+3
View File
@@ -19,6 +19,9 @@ static int open_passwd_file(const char *root, const char *fname, FILE **ret_file
_cleanup_close_ int fd = -EBADF;
_cleanup_fclose_ FILE *f = NULL;
assert(fname);
assert(ret_file);
fd = chase_and_open(fname, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC, &p);
if (fd < 0)
return fd;
+1
View File
@@ -42,6 +42,7 @@ static void test_resolve_one(const char *name) {
static int parse_argv(int argc, char *argv[], char ***ret_args) {
assert_se(argc >= 0);
assert_se(argv);
assert_se(ret_args);
OptionParser opts = { argc, argv };
+2
View File
@@ -1824,6 +1824,8 @@ int udev_rules_load(UdevRules **ret_rules, ResolveNameTiming resolve_name_timing
_cleanup_strv_free_ char **directories = NULL;
int r;
assert(ret_rules);
rules = udev_rules_new(resolve_name_timing);
if (!rules)
return -ENOMEM;
@@ -378,6 +378,9 @@ int xdg_autostart_format_exec_start(
bool first_arg;
int r;
assert(exec);
assert(ret_exec_start);
/*
* Unfortunately, there is a mismatch between systemd's idea of $PATH and XDGs. I.e. we need to
* ensure that we have an absolute path to support cases where $PATH has been modified from the