many: another set of checks for pointer access without NULL check (#41400)
Followup for https://github.com/systemd/systemd/pull/41370 Next set of pointer-deref coccinelle tweaks for: ''src/core/' 'src/journal/' 'src/network/' ''src/nspawn/'
This commit is contained in:
@@ -2978,11 +2978,7 @@ if spatch.found()
|
||||
# Remove directories from this list as they are cleaned up.
|
||||
coccinelle_exclude = [
|
||||
'src/basic/',
|
||||
'src/core/',
|
||||
'src/journal/',
|
||||
'src/libsystemd/',
|
||||
'src/network/',
|
||||
'src/nspawn/',
|
||||
'src/shared/',
|
||||
# libc/ has no assert() or systemd-headers so leave it
|
||||
'src/libc/',
|
||||
|
||||
@@ -8,6 +8,7 @@ Distribution=|ubuntu
|
||||
PrepareScripts=%D/mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.prepare
|
||||
Packages=
|
||||
clang-tidy
|
||||
coccinelle
|
||||
lcov
|
||||
mypy
|
||||
shellcheck
|
||||
|
||||
@@ -661,6 +661,8 @@ static int attach_custom_bpf_progs(Unit *u, const char *path, int attach_type, S
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
assert(set);
|
||||
assert(set_installed);
|
||||
|
||||
set_clear(*set_installed);
|
||||
r = set_ensure_allocated(set_installed, &bpf_program_hash_ops);
|
||||
|
||||
@@ -313,6 +313,8 @@ static int unit_compare_memory_limit(Unit *u, const char *property_name, uint64_
|
||||
* - ret_kernel_value will contain the actual value presented by the kernel. */
|
||||
|
||||
assert(u);
|
||||
assert(ret_unit_value);
|
||||
assert(ret_kernel_value);
|
||||
|
||||
/* The root slice doesn't have any controller files, so we can't compare anything. */
|
||||
if (unit_has_name(u, SPECIAL_ROOT_SLICE))
|
||||
@@ -3189,6 +3191,8 @@ static int cg_bpf_mask_supported(CGroupMask *ret) {
|
||||
CGroupMask mask = 0;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
/* BPF-based firewall, device access control, and pinned foreign prog */
|
||||
if (bpf_program_supported() > 0)
|
||||
mask |= CGROUP_MASK_BPF_FIREWALL |
|
||||
|
||||
@@ -240,6 +240,8 @@ int parse_emergency_action(
|
||||
|
||||
EmergencyAction x;
|
||||
|
||||
assert(ret);
|
||||
|
||||
x = emergency_action_from_string(value);
|
||||
if (x < 0)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -510,6 +510,8 @@ JobType job_type_collapse(JobType t, Unit *u) {
|
||||
int job_type_merge_and_collapse(JobType *a, JobType b, Unit *u) {
|
||||
JobType t;
|
||||
|
||||
assert(a);
|
||||
|
||||
t = job_type_lookup_merge(*a, b);
|
||||
if (t < 0)
|
||||
return -EEXIST;
|
||||
@@ -1523,6 +1525,11 @@ void job_add_to_gc_queue(Job *j) {
|
||||
}
|
||||
|
||||
static int job_compare_id(Job * const *a, Job * const *b) {
|
||||
assert(a);
|
||||
assert(b);
|
||||
assert(*a);
|
||||
assert(*b);
|
||||
|
||||
return CMP((*a)->id, (*b)->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,8 @@ static int parse_socket_protocol(const char *s) {
|
||||
int parse_crash_chvt(const char *value, int *data) {
|
||||
int b;
|
||||
|
||||
assert(data);
|
||||
|
||||
if (safe_atoi(value, data) >= 0)
|
||||
return 0;
|
||||
|
||||
@@ -107,6 +109,8 @@ int parse_confirm_spawn(const char *value, char **console) {
|
||||
char *s;
|
||||
int r;
|
||||
|
||||
assert(console);
|
||||
|
||||
r = value ? parse_boolean(value) : 1;
|
||||
if (r == 0) {
|
||||
*console = NULL;
|
||||
@@ -565,6 +569,8 @@ static int patch_var_run(
|
||||
const char *e;
|
||||
char *z;
|
||||
|
||||
assert(path);
|
||||
|
||||
e = path_startswith(*path, "/var/run/");
|
||||
if (!e)
|
||||
return 0;
|
||||
|
||||
@@ -1982,6 +1982,8 @@ Manager* manager_reloading_start(Manager *m) {
|
||||
}
|
||||
|
||||
void manager_reloading_stopp(Manager **m) {
|
||||
assert(m);
|
||||
|
||||
if (*m) {
|
||||
assert((*m)->n_reloading > 0);
|
||||
(*m)->n_reloading--;
|
||||
|
||||
@@ -2003,6 +2003,8 @@ static int mount_get_timeout(Unit *u, usec_t *timeout) {
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
assert(timeout);
|
||||
|
||||
if (!m->timer_event_source)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -931,6 +931,7 @@ static int activation_details_path_deserialize(const char *key, const char *valu
|
||||
|
||||
assert(key);
|
||||
assert(value);
|
||||
POINTER_MAY_BE_NULL(details);
|
||||
|
||||
if (!details || !*details)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -483,6 +483,8 @@ static int scope_get_timeout(Unit *u, usec_t *timeout) {
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
assert(timeout);
|
||||
|
||||
if (!s->timer_event_source)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ static int fdopen_unlocked_at(int dfd, const char *dir, const char *name, int *s
|
||||
int fd, r;
|
||||
FILE *f;
|
||||
|
||||
assert(status);
|
||||
assert(ret_file);
|
||||
|
||||
fd = openat(dfd, name, O_RDONLY|O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
if (*status == 0)
|
||||
|
||||
@@ -3525,6 +3525,8 @@ static int socket_get_timeout(Unit *u, usec_t *timeout) {
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
assert(timeout);
|
||||
|
||||
if (!s->timer_event_source)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -1427,6 +1427,8 @@ static int swap_get_timeout(Unit *u, usec_t *timeout) {
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
assert(timeout);
|
||||
|
||||
if (!s->timer_event_source)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -940,6 +940,7 @@ static int activation_details_timer_deserialize(const char *key, const char *val
|
||||
|
||||
assert(key);
|
||||
assert(value);
|
||||
POINTER_MAY_BE_NULL(details);
|
||||
|
||||
if (!details || !*details)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -6377,6 +6377,7 @@ int unit_clean(Unit *u, ExecCleanMask mask) {
|
||||
|
||||
int unit_can_clean(Unit *u, ExecCleanMask *ret) {
|
||||
assert(u);
|
||||
assert(ret);
|
||||
|
||||
if (!UNIT_VTABLE(u)->clean ||
|
||||
u->load_state != UNIT_LOADED) {
|
||||
|
||||
@@ -781,6 +781,9 @@ static int set_credential_build_json(sd_json_variant **ret, const char *name, vo
|
||||
int unit_exec_context_build_json(sd_json_variant **ret, const char *name, void *userdata) {
|
||||
Unit *u = ASSERT_PTR(userdata);
|
||||
ExecContext *c = unit_get_exec_context(u);
|
||||
|
||||
assert(ret);
|
||||
|
||||
if (!c) {
|
||||
*ret = NULL;
|
||||
return 0;
|
||||
|
||||
@@ -154,9 +154,7 @@ static int normalize_offset(
|
||||
POINTER_MAY_BE_NULL(compressed);
|
||||
POINTER_MAY_BE_NULL(compressed_size);
|
||||
|
||||
uint64_t q;
|
||||
|
||||
q = be64toh(p);
|
||||
uint64_t q = be64toh(p);
|
||||
|
||||
if (q & QCOW2_COMPRESSED) {
|
||||
uint64_t sz, csize_shift, csize_mask;
|
||||
|
||||
@@ -158,6 +158,8 @@ static int map_generic_field(
|
||||
char *c, *t;
|
||||
int r;
|
||||
|
||||
assert(p);
|
||||
|
||||
/* Implements fallback mappings for all fields we don't know */
|
||||
|
||||
for (e = *p; e < *p + 16; e++) {
|
||||
|
||||
@@ -135,6 +135,8 @@ static int manager_determine_path_usage(
|
||||
}
|
||||
|
||||
static void cache_space_invalidate(JournalStorageSpace *space) {
|
||||
assert(space);
|
||||
|
||||
zero(*space);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,10 @@ static void manager_process_entry_meta(
|
||||
char **message,
|
||||
pid_t *object_pid) {
|
||||
|
||||
assert(priority);
|
||||
assert(identifier);
|
||||
assert(message);
|
||||
|
||||
/* We need to determine the priority of this entry for the rate limiting logic */
|
||||
|
||||
if (l == 10 &&
|
||||
@@ -113,6 +117,8 @@ static int manager_process_entry(
|
||||
const char *p;
|
||||
int r = 1;
|
||||
|
||||
assert(remaining);
|
||||
|
||||
p = buffer;
|
||||
|
||||
while (*remaining > 0) {
|
||||
|
||||
@@ -119,6 +119,7 @@ static int address_new(
|
||||
assert(network);
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(addr);
|
||||
POINTER_MAY_BE_NULL(peer);
|
||||
|
||||
address = new(Address, 1);
|
||||
if (!address)
|
||||
|
||||
@@ -125,6 +125,7 @@ static int macsec_receive_channel_new(MACsec *s, uint64_t sci, ReceiveChannel **
|
||||
ReceiveChannel *c;
|
||||
|
||||
assert(s);
|
||||
assert(ret);
|
||||
|
||||
c = new(ReceiveChannel, 1);
|
||||
if (!c)
|
||||
|
||||
@@ -277,6 +277,7 @@ static int netdev_attach_name_full(NetDev *netdev, const char *name, Hashmap **n
|
||||
|
||||
assert(netdev);
|
||||
assert(name);
|
||||
assert(netdevs);
|
||||
|
||||
r = hashmap_ensure_put(netdevs, &string_hash_ops, name, netdev);
|
||||
if (r == -ENOMEM)
|
||||
|
||||
@@ -20,6 +20,9 @@ static int ifindex_str_compare_func(char * const *a, char * const *b) {
|
||||
size_t al, bl;
|
||||
int r;
|
||||
|
||||
assert(a);
|
||||
assert(b);
|
||||
|
||||
al = strlen_ptr(*a);
|
||||
bl = strlen_ptr(*b);
|
||||
|
||||
|
||||
@@ -276,6 +276,7 @@ int link_get_captive_portal(Link *link, const char **ret) {
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(ret);
|
||||
|
||||
if (!link->network) {
|
||||
*ret = NULL;
|
||||
|
||||
@@ -557,6 +557,7 @@ static int dhcp_pd_get_preferred_subnet_prefix(
|
||||
assert(link->manager);
|
||||
assert(link->network);
|
||||
assert(pd_prefix);
|
||||
assert(ret);
|
||||
|
||||
if (link->network->dhcp_pd_subnet_id >= 0) {
|
||||
/* If the link has a preference for a particular subnet id try to allocate that */
|
||||
|
||||
@@ -326,6 +326,7 @@ void manager_toggle_dhcp4_server_state(Manager *manager, bool start) {
|
||||
|
||||
static int dhcp_server_find_uplink(Link *link, Link **ret) {
|
||||
assert(link);
|
||||
assert(ret);
|
||||
|
||||
if (link->network->dhcp_server_uplink_name)
|
||||
return link_get_by_name(link->manager, link->network->dhcp_server_uplink_name, ret);
|
||||
|
||||
@@ -862,6 +862,7 @@ static int link_put_carrier(Link *link, Link *carrier, Hashmap **h) {
|
||||
|
||||
assert(link);
|
||||
assert(carrier);
|
||||
assert(h);
|
||||
|
||||
if (link == carrier)
|
||||
return 0;
|
||||
|
||||
@@ -423,6 +423,7 @@ static int radv_find_uplink(Link *link, Link **ret) {
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(ret);
|
||||
|
||||
if (link->network->router_uplink_name)
|
||||
return link_get_by_name(link->manager, link->network->router_uplink_name, ret);
|
||||
|
||||
@@ -99,6 +99,8 @@ DEFINE_SECTION_CLEANUP_FUNCTIONS(RoutingPolicyRule, routing_policy_rule_unref);
|
||||
static int routing_policy_rule_new(RoutingPolicyRule **ret) {
|
||||
RoutingPolicyRule *rule;
|
||||
|
||||
assert(ret);
|
||||
|
||||
rule = new(RoutingPolicyRule, 1);
|
||||
if (!rule)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -235,6 +235,7 @@ int link_get_modem(Link *link, Modem **ret) {
|
||||
assert(link);
|
||||
assert(link->manager);
|
||||
assert(link->ifname);
|
||||
assert(ret);
|
||||
|
||||
HASHMAP_FOREACH(modem, link->manager->modems_by_path)
|
||||
if (modem->port_name && streq(modem->port_name, link->ifname)) {
|
||||
|
||||
@@ -1489,6 +1489,8 @@ static int oci_resources(const char *name, sd_json_variant *v, sd_json_dispatch_
|
||||
static bool sysctl_key_valid(const char *s) {
|
||||
bool dot = true;
|
||||
|
||||
POINTER_MAY_BE_NULL(s);
|
||||
|
||||
/* Note that we are a bit stricter here than in systemd-sysctl, as that inherited semantics from the old sysctl
|
||||
* tool, which were really weird (as it swaps / and . in both ways) */
|
||||
|
||||
@@ -1546,7 +1548,6 @@ static int oci_sysctl(const char *name, sd_json_variant *v, sd_json_dispatch_fla
|
||||
|
||||
#if HAVE_SECCOMP
|
||||
static int oci_seccomp_action_from_string(const char *name, uint32_t *ret) {
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
uint32_t action;
|
||||
@@ -1563,6 +1564,8 @@ static int oci_seccomp_action_from_string(const char *name, uint32_t *ret) {
|
||||
* here */
|
||||
};
|
||||
|
||||
assert(ret);
|
||||
|
||||
FOREACH_ELEMENT(i, table)
|
||||
if (streq_ptr(name, i->name)) {
|
||||
*ret = i->action;
|
||||
@@ -1573,7 +1576,6 @@ static int oci_seccomp_action_from_string(const char *name, uint32_t *ret) {
|
||||
}
|
||||
|
||||
static int oci_seccomp_arch_from_string(const char *name, uint32_t *ret) {
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
uint32_t arch;
|
||||
@@ -1605,6 +1607,8 @@ static int oci_seccomp_arch_from_string(const char *name, uint32_t *ret) {
|
||||
{ "SCMP_ARCH_X86_64", SCMP_ARCH_X86_64 },
|
||||
};
|
||||
|
||||
assert(ret);
|
||||
|
||||
FOREACH_ELEMENT(i, table)
|
||||
if (streq_ptr(i->name, name)) {
|
||||
*ret = i->arch;
|
||||
@@ -1615,7 +1619,6 @@ static int oci_seccomp_arch_from_string(const char *name, uint32_t *ret) {
|
||||
}
|
||||
|
||||
static int oci_seccomp_compare_from_string(const char *name, enum scmp_compare *ret) {
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
enum scmp_compare op;
|
||||
@@ -1629,6 +1632,8 @@ static int oci_seccomp_compare_from_string(const char *name, enum scmp_compare *
|
||||
{ "SCMP_CMP_MASKED_EQ", SCMP_CMP_MASKED_EQ },
|
||||
};
|
||||
|
||||
assert(ret);
|
||||
|
||||
FOREACH_ELEMENT(i, table)
|
||||
if (streq_ptr(i->name, name)) {
|
||||
*ret = i->op;
|
||||
|
||||
@@ -2981,6 +2981,7 @@ static int wait_for_container(PidRef *pid, ContainerStatus *container) {
|
||||
int r;
|
||||
|
||||
assert(pidref_is_set(pid));
|
||||
assert(container);
|
||||
|
||||
r = pidref_wait_for_terminate(pid, &status);
|
||||
if (r < 0)
|
||||
@@ -4723,6 +4724,8 @@ static int nspawn_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t r
|
||||
static int setup_notify_parent(sd_event *event, int fd, PidRef *inner_child_pid, sd_event_source **notify_event_source) {
|
||||
int r;
|
||||
|
||||
assert(notify_event_source);
|
||||
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -83,9 +83,7 @@ int dns_stub_listener_extra_new(
|
||||
|
||||
assert(ret);
|
||||
|
||||
DnsStubListenerExtra *l;
|
||||
|
||||
l = new(DnsStubListenerExtra, 1);
|
||||
DnsStubListenerExtra *l = new(DnsStubListenerExtra, 1);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user