]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: make check-pointer-deref clean 41400/head
authorMichael Vogt <michael@amutable.com>
Sat, 28 Mar 2026 11:35:54 +0000 (12:35 +0100)
committerMichael Vogt <michael@amutable.com>
Mon, 30 Mar 2026 12:18:56 +0000 (14:18 +0200)
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.

16 files changed:
meson.build
src/core/bpf-firewall.c
src/core/cgroup.c
src/core/emergency-action.c
src/core/job.c
src/core/load-fragment.c
src/core/manager.c
src/core/mount.c
src/core/path.c
src/core/scope.c
src/core/smack-setup.c
src/core/socket.c
src/core/swap.c
src/core/timer.c
src/core/unit.c
src/core/varlink-execute.c

index 674c2fef64f11cfadc2b810c19aeca35fc738b91..c9e96b259149585a55258e92fe9dee9e98df50d0 100644 (file)
@@ -2978,7 +2978,6 @@ if spatch.found()
         # Remove directories from this list as they are cleaned up.
         coccinelle_exclude = [
                 'src/basic/',
-                'src/core/',
                 'src/libsystemd/',
                 'src/shared/',
                 # libc/ has no assert() or systemd-headers so leave it
index b0c54d313472357d14fd15649c9c69f180152c23..bc5d7f0351dcd3e101366ac1205b7ec2289fa3b3 100644 (file)
@@ -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);
index 514dabf371b7fb2230b1d07cadbe6fe6b549cf23..7bcd6777df244b9d214e5c3fa538bdc685a1671f 100644 (file)
@@ -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 |
index 439228c8995ff7fd572549be3dc403ed1d183181..b9a5c66ebff87472d1ac28708e23d1a0bb78ca63 100644 (file)
@@ -240,6 +240,8 @@ int parse_emergency_action(
 
         EmergencyAction x;
 
+        assert(ret);
+
         x = emergency_action_from_string(value);
         if (x < 0)
                 return -EINVAL;
index 1cac09bd06607a0758f9ace9a7e2241b81a21098..638e6e759e5b24a308e3c2407ba69b37f527e9be 100644 (file)
@@ -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);
 }
 
index cef01ab776365413339c22655bf03ec4fe8a4511..840804fcf8ddeebcd72206e53ef404d9a578daee 100644 (file)
@@ -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;
index e8c5f008958474ae0452f17c762a3a82c3866851..a5af434e5ef8151a38e2f552b1481fcca6e010d4 100644 (file)
@@ -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--;
index 680e376febfc9c5252508fd146a43697bb836343..46e157af206c1d1bb8e9f47ad0664fa3e6793285 100644 (file)
@@ -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;
 
index 789ef9e25d6e93faf3bc9c1211b858166cc27743..18a5e140f144244a009686db7914081487e7bcc0 100644 (file)
@@ -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;
index d36b27c537dfc51de9f427c8ed6372a7a5496f9b..21520d9d1943b994a3f7b01af70cbed876f29869 100644 (file)
@@ -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;
 
index 1e8e2b54e53d2ac5bca9d246f764de57d813f8d1..46c7d0a6e88d2e3662256aafab29196fb0c6dd27 100644 (file)
@@ -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)
index 43f61e456dcf2dc71000ce3667d00fed8d32733d..f911f1758fb96898edefc4dfd1fa92dc0962fbc2 100644 (file)
@@ -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;
 
index 5de1dccf42779159912e38fae85cddda3bc51e8d..960d831c5cc3d3fce4744c9ff23936ffc7f5bb77 100644 (file)
@@ -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;
 
index c591fcd469c7a25a67ab252640813451cc2723d3..510d8e199577420d723ffb604feae6e07c4ae196 100644 (file)
@@ -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;
index 9af7fb51405e044dd21dca8ede4bbae030433873..41f536ce1f15ddcbe87abe953d4434e14e148f0c 100644 (file)
@@ -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) {
index e6efd5989597b210d2b3400c9f604e0b5b9dcca7..ccb454c8c245bd51b200c465e8a4641d086242d6 100644 (file)
@@ -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;