]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libsystemd: make check-pointer-deref clean
authorMichael Vogt <michael@amutable.com>
Sat, 28 Mar 2026 20:45:01 +0000 (21:45 +0100)
committerMichael Vogt <michael@amutable.com>
Tue, 31 Mar 2026 16:30:40 +0000 (18:30 +0200)
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.

17 files changed:
meson.build
src/libsystemd/sd-bus/bus-creds.c
src/libsystemd/sd-bus/bus-error.c
src/libsystemd/sd-bus/bus-internal.c
src/libsystemd/sd-bus/bus-introspect.c
src/libsystemd/sd-bus/bus-objects.c
src/libsystemd/sd-bus/bus-socket.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-bus/test-bus-objects.c
src/libsystemd/sd-bus/test-bus-vtable.c
src/libsystemd/sd-device/device-monitor.c
src/libsystemd/sd-event/sd-event.c
src/libsystemd/sd-id128/id128-util.c
src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-journal/journal-verify.c
src/libsystemd/sd-journal/test-journal-interleaving.c
src/libsystemd/sd-netlink/netlink-message-rtnl.c

index c9e96b259149585a55258e92fe9dee9e98df50d0..0e78ccaac8ec37cf44c94903e41bf7acd28547d3 100644 (file)
@@ -2978,7 +2978,6 @@ if spatch.found()
         # Remove directories from this list as they are cleaned up.
         coccinelle_exclude = [
                 'src/basic/',
-                'src/libsystemd/',
                 'src/shared/',
                 # libc/ has no assert() or systemd-headers so leave it
                 'src/libc/',
index 0812dc532477cf2d2516724a29f419ca48e8acae..0b2a402251cb61262856a1b378c4b332b02857a6 100644 (file)
@@ -358,6 +358,7 @@ _public_ int sd_bus_creds_get_tid(sd_bus_creds *c, pid_t *ret) {
 
 _public_ int sd_bus_creds_get_selinux_context(sd_bus_creds *c, const char **ret) {
         assert_return(c, -EINVAL);
+        assert_return(ret, -EINVAL);
 
         if (!(c->mask & SD_BUS_CREDS_SELINUX_CONTEXT))
                 return -ENODATA;
index bc0164c1b4ebb2d60c00b7c9e6f302cfce64f3bd..be64e4a6c8bc023ad974c8a0f2887e0d16bb7896 100644 (file)
@@ -165,6 +165,8 @@ static int errno_to_bus_error_name_new(int error, char **ret) {
         const char *name;
         char *n;
 
+        assert(ret);
+
         /* D-Bus names must not start with a digit. Thus, an name like System.Error.500 would not be legal.
          * Let's just return 0 if an unknown errno is encountered, which will cause the caller to fall back
          * to BUS_ERROR_FAILED.
index 4bcebeedb22f9a3ea46e04d8d8a342596f19bcd4..3d28d885557a8cd638e0606686e35b6f97ecb365 100644 (file)
@@ -263,6 +263,8 @@ bool path_simple_pattern(const char *pattern, const char *value) {
 }
 
 int bus_message_type_from_string(const char *s, uint8_t *u) {
+        assert(u);
+
         if (streq(s, "signal"))
                 *u = SD_BUS_MESSAGE_SIGNAL;
         else if (streq(s, "method_call"))
index cdc869ce0496a26166987013a8437f09526ab5a3..d66c3a704db5dd495c26b4956db90b98e702f684 100644 (file)
@@ -175,6 +175,8 @@ static int introspect_write_arguments(BusIntrospect *i, const char *signature, c
 
         assert(i);
         assert(i->m.f);
+        assert(signature);
+        assert(names);
 
         for (;;) {
                 size_t l;
index 42e2332001b8a26d8b168ccf07021c83377f0ae0..83ba3a523992b8699d5dac1289ffea98ea9e4b1d 100644 (file)
@@ -1704,6 +1704,10 @@ typedef enum {
 static bool names_are_valid(const char *signature, const char **names, names_flags *flags) {
         int r;
 
+        assert(signature);
+        assert(names);
+        assert(flags);
+
         if ((*flags & NAMES_FIRST_PART || *flags & NAMES_SINGLE_PART) && **names != '\0')
                 *flags |= NAMES_PRESENT;
 
index fdbf557f137cf7809ef19ea4415faba39ad9c593..3c5f596440ec913eaf3dd91f924d66260c6b4ef5 100644 (file)
@@ -35,6 +35,7 @@
 #define SNDBUF_SIZE (8*1024*1024)
 
 static void iovec_advance(struct iovec iov[], unsigned *idx, size_t size) {
+        assert(idx);
 
         while (size > 0) {
                 struct iovec *i = iov + *idx;
index 2a3ea8eb8f35623939596adcc9cd44e3d10e7c18..27f788d99557642b0834d1bb653febf08bd4289e 100644 (file)
@@ -2021,6 +2021,7 @@ static int bus_write_message(sd_bus *bus, sd_bus_message *m, size_t *idx) {
 
         assert(bus);
         assert(m);
+        assert(idx);
 
         r = bus_socket_write_message(bus, m, idx);
         if (r <= 0)
index 62050b103db234efa2ad2328fa73bf85c031f3b2..4ad60f0d582252c906f2bca04b94e08f042376e8 100644 (file)
@@ -177,6 +177,7 @@ static const sd_bus_vtable vtable2[] = {
 };
 
 static int enumerator_callback(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *reterr_error) {
+        assert(nodes);
 
         if (object_path_startswith("/value", path))
                 ASSERT_NOT_NULL(*nodes = strv_new("/value/c", "/value/b", "/value/a"));
@@ -185,6 +186,7 @@ static int enumerator_callback(sd_bus *bus, const char *path, void *userdata, ch
 }
 
 static int enumerator2_callback(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *reterr_error) {
+        assert(nodes);
 
         if (object_path_startswith("/value/a", path))
                 ASSERT_NOT_NULL(*nodes = strv_new("/value/a/z", "/value/a/x", "/value/a/y"));
@@ -195,6 +197,8 @@ static int enumerator2_callback(sd_bus *bus, const char *path, void *userdata, c
 static int enumerator3_callback(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *reterr_error) {
         _cleanup_strv_free_ char **v = NULL;
 
+        assert(nodes);
+
         if (!object_path_startswith("/value/b", path))
                 return 1;
 
index ae2ead550f9e2d89f495db411b6eaf26fd0e6506..84e75cd1e31a1e39f9b5e6db043149e7317df03f 100644 (file)
@@ -22,6 +22,7 @@ static struct context c = {};
 static int happy_finder_object = 0;
 
 static int happy_finder(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *reterr_error) {
+        assert(found);
         assert(userdata);
         assert(userdata == &c);
 
index 67d68bb07f9ab67eb4e3c7bacd2322d95ad50ce0..962329a865ebd90af7259f1adb1e344e3a935d79 100644 (file)
@@ -783,6 +783,8 @@ int device_monitor_send(
 
 static void bpf_stmt(struct sock_filter *ins, unsigned *i,
                      unsigned short code, unsigned data) {
+        assert(i);
+
         ins[(*i)++] = (struct sock_filter) {
                 .code = code,
                 .k = data,
@@ -792,6 +794,8 @@ static void bpf_stmt(struct sock_filter *ins, unsigned *i,
 static void bpf_jmp(struct sock_filter *ins, unsigned *i,
                     unsigned short code, unsigned data,
                     unsigned short jt, unsigned short jf) {
+        assert(i);
+
         ins[(*i)++] = (struct sock_filter) {
                 .code = code,
                 .jt = jt,
index 6867385e92a64bbaecab01d9d9f4e48b6441ca5d..ad82f308baac521f22f43ea05204a32287781f3f 100644 (file)
@@ -5077,6 +5077,7 @@ _public_ int sd_event_get_watchdog(sd_event *e) {
 _public_ int sd_event_get_iteration(sd_event *e, uint64_t *ret) {
         assert_return(e, -EINVAL);
         assert_return(e = event_resolve(e), -ENOPKG);
+        assert_return(ret, -EINVAL);
         assert_return(!event_origin_changed(e), -ECHILD);
 
         *ret = e->iteration;
index 9d406a45d1316741c512037d1c45106745ba56f9..700c9268edac5e855dc6134a94a2ba49021efde7 100644 (file)
@@ -199,6 +199,8 @@ int id128_write_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t id) {
 }
 
 void id128_hash_func(const sd_id128_t *p, struct siphash *state) {
+        assert(p);
+
         siphash24_compress_typesafe(*p, state);
 }
 
index b4efcc050eaaeb928b280690d6423ff7e64f57d1..363df258a17709fb3a3dbe4e5f06a7f8a932e01a 100644 (file)
@@ -2107,6 +2107,8 @@ static int link_entry_into_array(
         assert(f->header);
         assert(first);
         assert(idx);
+        POINTER_MAY_BE_NULL(tail);
+        POINTER_MAY_BE_NULL(tidx);
         assert(p > 0);
 
         a = tail ? le32toh(*tail) : le64toh(*first);
index 0afb664896acacbf6a4f6a5fa3940d3431e60320..1b3bf3fca35cb7f2e5f0e5f58a02c5a0b91ae2bc 100644 (file)
@@ -23,6 +23,8 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
         unsigned n, i, j, k;
         usec_t z, x;
 
+        assert(last_usec);
+
         if (!on_tty())
                 return;
 
index fbbaa82850db6b3fa5ba144d27fdb003128a9a1c..b0d7e80b116bb3cea5e397b3c40bb1c9525afe9c 100644 (file)
@@ -591,6 +591,8 @@ TEST(sequence_numbers) {
 }
 
 static int expected_result(uint64_t needle, const uint64_t *candidates, const uint64_t *offset, size_t n, direction_t direction, uint64_t *ret) {
+        assert(ret);
+
         switch (direction) {
         case DIRECTION_DOWN:
                 for (size_t i = 0; i < n; i++) {
@@ -625,6 +627,8 @@ static int expected_result(uint64_t needle, const uint64_t *candidates, const ui
 }
 
 static int expected_result_next(uint64_t needle, const uint64_t *candidates, const uint64_t *offset, size_t n, direction_t direction, uint64_t *ret) {
+        assert(ret);
+
         switch (direction) {
         case DIRECTION_DOWN:
                 for (size_t i = 0; i < n; i++)
index f1871ceb822e385ce15e8249c8908eff350d5648..af1d6fd3f5a12398229e4d7d80d991dfbb0da3ef 100644 (file)
@@ -385,6 +385,8 @@ int sd_rtnl_message_new_addr_update(
                 int family) {
         int r;
 
+        assert_return(ret, -EINVAL);
+
         r = sd_rtnl_message_new_addr(rtnl, ret, RTM_NEWADDR, ifindex, family);
         if (r < 0)
                 return r;